Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
jlo jlo is offline
external usenet poster
 
Posts: 10
Default Automate a Text Form Field

I have created a template using the Forms toolbar. I have a text form field
that the user will type their email address in. When the user is done typing
in their email address, is there a way for this field to launch Outlook and
populate the email address in the To: box so the form can be emailed?

Thanks!
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Automate a Text Form Field

Are you saying that you want the user to mail the document to himself ...or
to you ... or to someone else?
The basic code is:

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = " 'send to this address
.Subject = "New subject" 'This is the message subject
.Body = "See attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

which will work to send the document to you, if you put your address in the
send to line. If you want to send it to the address the user enters then you
need a couple of extra lines of code

After the line
Dim oItem As Outlook.MailItem
enter
Dim eAdd As String
eAdd =
ActiveDocument.FormFields("Bookmark_Name_of_form_f ield_with_the_address").Result

and replace

with
eAdd

(no quotes around aAdd)

You can run the macro on exit from the form field. The only problem you will
have is getting the user to accept the macro. There is no way to force a
user to run macros.

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
I have created a template using the Forms toolbar. I have a text
form field that the user will type their email address in. When the
user is done typing in their email address, is there a way for this
field to launch Outlook and populate the email address in the To: box
so the form can be emailed?

Thanks!



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
jlo jlo is offline
external usenet poster
 
Posts: 10
Default Automate a Text Form Field

Another user

"Graham Mayor" wrote:

Are you saying that you want the user to mail the document to himself ...or
to you ... or to someone else?
The basic code is:

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = " 'send to this address
.Subject = "New subject" 'This is the message subject
.Body = "See attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

which will work to send the document to you, if you put your address in the
send to line. If you want to send it to the address the user enters then you
need a couple of extra lines of code

After the line
Dim oItem As Outlook.MailItem
enter
Dim eAdd As String
eAdd =
ActiveDocument.FormFields("Bookmark_Name_of_form_f ield_with_the_address").Result

and replace

with
eAdd

(no quotes around aAdd)

You can run the macro on exit from the form field. The only problem you will
have is getting the user to accept the macro. There is no way to force a
user to run macros.

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
I have created a template using the Forms toolbar. I have a text
form field that the user will type their email address in. When the
user is done typing in their email address, is there a way for this
field to launch Outlook and populate the email address in the To: box
so the form can be emailed?

Thanks!




  #4   Report Post  
Posted to microsoft.public.word.docmanagement
jlo jlo is offline
external usenet poster
 
Posts: 10
Default Automate a Text Form Field

Thank you Graham for the code. When it tries to run I get the following
error: User-defined type not defined on the line:

Dim oOutlookApp As Outlook.Application

"jlo" wrote:

Another user

"Graham Mayor" wrote:

Are you saying that you want the user to mail the document to himself ...or
to you ... or to someone else?
The basic code is:

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = " 'send to this address
.Subject = "New subject" 'This is the message subject
.Body = "See attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

which will work to send the document to you, if you put your address in the
send to line. If you want to send it to the address the user enters then you
need a couple of extra lines of code

After the line
Dim oItem As Outlook.MailItem
enter
Dim eAdd As String
eAdd =
ActiveDocument.FormFields("Bookmark_Name_of_form_f ield_with_the_address").Result

and replace

with
eAdd

(no quotes around aAdd)

You can run the macro on exit from the form field. The only problem you will
have is getting the user to accept the macro. There is no way to force a
user to run macros.

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
I have created a template using the Forms toolbar. I have a text
form field that the user will type their email address in. When the
user is done typing in their email address, is there a way for this
field to launch Outlook and populate the email address in the To: box
so the form can be emailed?

Thanks!




  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Automate a Text Form Field

Oops - my deliberate mistake. You must check the Outlook object library in
vba Tools references.
Apologies for the oversight

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
Thank you Graham for the code. When it tries to run I get the
following error: User-defined type not defined on the line:

Dim oOutlookApp As Outlook.Application

"jlo" wrote:

Another user

"Graham Mayor" wrote:

Are you saying that you want the user to mail the document to
himself ...or to you ... or to someone else?
The basic code is:

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = " 'send to this address
.Subject = "New subject" 'This is the message subject
.Body = "See attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName,
Type:=olByValue .Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

which will work to send the document to you, if you put your
address in the send to line. If you want to send it to the address
the user enters then you need a couple of extra lines of code

After the line
Dim oItem As Outlook.MailItem
enter
Dim eAdd As String
eAdd =
ActiveDocument.FormFields("Bookmark_Name_of_form_f ield_with_the_address").Result

and replace

with
eAdd

(no quotes around aAdd)

You can run the macro on exit from the form field. The only problem
you will have is getting the user to accept the macro. There is no
way to force a user to run macros.

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
I have created a template using the Forms toolbar. I have a text
form field that the user will type their email address in. When
the user is done typing in their email address, is there a way for
this field to launch Outlook and populate the email address in the
To: box so the form can be emailed?

Thanks!





  #6   Report Post  
Posted to microsoft.public.word.docmanagement
jlo jlo is offline
external usenet poster
 
Posts: 10
Default Automate a Text Form Field

It works!!! Thank you so much!!! How in the world you know this stuff is
beyond me. I appreciate you sharing!!

"Graham Mayor" wrote:

Oops - my deliberate mistake. You must check the Outlook object library in
vba Tools references.
Apologies for the oversight

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
Thank you Graham for the code. When it tries to run I get the
following error: User-defined type not defined on the line:

Dim oOutlookApp As Outlook.Application

"jlo" wrote:

Another user

"Graham Mayor" wrote:

Are you saying that you want the user to mail the document to
himself ...or to you ... or to someone else?
The basic code is:

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = " 'send to this address
.Subject = "New subject" 'This is the message subject
.Body = "See attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName,
Type:=olByValue .Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

which will work to send the document to you, if you put your
address in the send to line. If you want to send it to the address
the user enters then you need a couple of extra lines of code

After the line
Dim oItem As Outlook.MailItem
enter
Dim eAdd As String
eAdd =
ActiveDocument.FormFields("Bookmark_Name_of_form_f ield_with_the_address").Result

and replace

with
eAdd

(no quotes around aAdd)

You can run the macro on exit from the form field. The only problem
you will have is getting the user to accept the macro. There is no
way to force a user to run macros.

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
I have created a template using the Forms toolbar. I have a text
form field that the user will type their email address in. When
the user is done typing in their email address, is there a way for
this field to launch Outlook and populate the email address in the
To: box so the form can be emailed?

Thanks!




  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Automate a Text Form Field

You are welcome

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
It works!!! Thank you so much!!! How in the world you know this stuff
is beyond me. I appreciate you sharing!!

"Graham Mayor" wrote:

Oops - my deliberate mistake. You must check the Outlook object
library in vba Tools references.
Apologies for the oversight

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
Thank you Graham for the code. When it tries to run I get the
following error: User-defined type not defined on the line:

Dim oOutlookApp As Outlook.Application

"jlo" wrote:

Another user

"Graham Mayor" wrote:

Are you saying that you want the user to mail the document to
himself ...or to you ... or to someone else?
The basic code is:

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = " 'send to this address
.Subject = "New subject" 'This is the message subject
.Body = "See attached document" ' This is the message body
text .Attachments.Add Source:=ActiveDocument.FullName,
Type:=olByValue .Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

which will work to send the document to you, if you put your
address in the send to line. If you want to send it to the address
the user enters then you need a couple of extra lines of code

After the line
Dim oItem As Outlook.MailItem
enter
Dim eAdd As String
eAdd =
ActiveDocument.FormFields("Bookmark_Name_of_form_f ield_with_the_address").Result

and replace

with
eAdd

(no quotes around aAdd)

You can run the macro on exit from the form field. The only
problem you will have is getting the user to accept the macro.
There is no way to force a user to run macros.

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



jlo wrote:
I have created a template using the Forms toolbar. I have a text
form field that the user will type their email address in. When
the user is done typing in their email address, is there a way
for this field to launch Outlook and populate the email address
in the To: box so the form can be emailed?

Thanks!



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate a form by saving macros in the form template...? Natalie W. Microsoft Word Help 1 April 27th 07 07:26 PM
File Name Field With Text Form Field When Performing a Save As... Bilbert Microsoft Word Help 1 April 11th 07 08:50 PM
Copy portion of text form field , the field is in a table cell otilia Tables 6 January 27th 06 11:52 AM
auto add text from one form field to another form field in same do cineck Microsoft Word Help 1 January 17th 06 02:32 AM
Autofill of Text Form Field based on another Text Form Field Brett Kinross Microsoft Word Help 3 November 24th 05 03:49 AM


All times are GMT +1. The time now is 02:26 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"