|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How do you add a line from a fillable word document into a VBA that you are using to email out
Hi everyone,
How do you add a line from a fillable word document into a VBA that you are using to email out that said document? I have a VBA but I want to enter the name of the person completing the form from a line in the form into the body text of the email. (if that makes sense) my VBA is: Private Sub CommandButton1_Click() Dim OL As Object Dim EmailItem As Object Dim Doc As Document Application.ScreenUpdating = False Set OL = CreateObject("Outlook.Application") Set EmailItem = OL.CreateItem(olMailItem) Set Doc = ActiveDocument Doc.Save With EmailItem .Subject = "Referral" Dim sMsgBody As String sMsgBody = sMsgBody & "Dear Team" & vbCr & vbCr sMsgBody = sMsgBody & "Please find attached my completed referral form for a woman to your services" & vbCr & vbCr sMsgBody = sMsgBody & "Kind Regards," & vbCr .body = sMsgBody .To = "person@person.com" .Importance = 1 .Attachments.Add Doc.FullName .Send End With Application.ScreenUpdating = True Set Doc = Nothing Set OL = Nothing Set EmailItem = Nothing End Sub |
#2
|
|||
|
|||
What are you using as the "fillable" field? If you use as content controls titles say "Author" then you could use:
Code:
sMsgBody = sMsgBody & "Please find attached my completed referral form for a woman to your services" & vbCr & vbCr sMsgBody = sMsgBody & "Kind Regards," & vbCr sMsgBox = sMsgBody & Doc.SelectContentControlsByTitle("Author").Item(1).Range.Text .body = sMsgBody |
#3
|
|||
|
|||
@gmaxey
Thank you for this, I was using content controls so I changed the tag to author. It didn't work initially but noticed you had a typo (smsgbox) that I changed and works perfectly |
#4
|
|||
|
|||
I believe that "Author" is the name of a built-in Document Property Content Control that you could use instead. See Repeating Data Using Document Properties Content Controls and Other Mapped Content Controls.
It is filled with whatever would normally show up in the Author Document Property unless changed. On my documents, it is my Word username by default. You could also get that name from the system if you do not want it changed by the user. |
Tags |
vba word outlook email |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to make a fillable word template but not see what is not req'd to be filled in saved as document | sjohnstone@edgeautomation | Word | 1 | 05-02-2017 10:05 AM |
Protect fillable word 2013 document | metsmaniac | Word | 1 | 06-30-2016 12:35 PM |
Word 2010 - How to create a fillable document from a boilerplate document | sheaters | Word | 2 | 05-04-2016 01:57 PM |
How to make uneditable but fillable document in word 2003? | officeboy09 | Word | 1 | 01-22-2014 03:54 PM |
Put a document in word into a fillable form | groovy chick | Word | 3 | 01-18-2012 04:49 AM |