Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Automate a form by saving macros in the form template...? | Microsoft Word Help | |||
File Name Field With Text Form Field When Performing a Save As... | Microsoft Word Help | |||
Copy portion of text form field , the field is in a table cell | Tables | |||
auto add text from one form field to another form field in same do | Microsoft Word Help | |||
Autofill of Text Form Field based on another Text Form Field | Microsoft Word Help |