Loss1003
12-29-2015, 09:31 AM
I have word 2010 document that includes form fields. I’d like to send the document into outlook and have the subject line name pulled from one of the text form fields (bookmark as Aname & PolNum). The following code works except the subject includes the wording (FORMTEXT) before the aname and PolNum. I've tried protecting and unprotecting the document to see if that helped. Thanks for your help.
Sub sendeMail()
Dim olkApp As Object
Dim strSubject As String
Dim strTo As String
Dim strBody As String
Dim strAtt As String
' Dim Temp As String
' Temp = ActiveDocument.FormFields("Text1").Result
' ActiveDocument.FormFields("Text2").Result = Temp
' strSubject = "Whatever!"
strSubject = "Quality Questionnaire" & " - " & ActiveDocument.Bookmarks("Aname").Range.Text & " - " & ActiveDocument.Bookmarks("PolNum").Range.Text
strBody = "In striving to provide the best information possible to our associates, we ask you to please take five minutes to fill out this questionnaire and Email the completed form to: MKLLosscontrolQQ@markelcorp.com"
strTo = ""
If ActiveDocument.Fullname = "" Then
MsgBox "activedocument not saved, exiting"
Exit Sub
Else
If MsgBox("Activedocument NOT saved, Proceed?", vbYesNo, "Error") <> vbYes Then Exit Sub
End If
strAtt = ActiveDocument.Fullname
Set olkApp = CreateObject("outlook.application")
With olkApp.createitem(0)
.to = strTo
.Subject = strSubject
.body = strBody
.attachments.Add strAtt
'.send
.Display
End With
Set olkApp = Nothing
End Sub
Sub sendeMail()
Dim olkApp As Object
Dim strSubject As String
Dim strTo As String
Dim strBody As String
Dim strAtt As String
' Dim Temp As String
' Temp = ActiveDocument.FormFields("Text1").Result
' ActiveDocument.FormFields("Text2").Result = Temp
' strSubject = "Whatever!"
strSubject = "Quality Questionnaire" & " - " & ActiveDocument.Bookmarks("Aname").Range.Text & " - " & ActiveDocument.Bookmarks("PolNum").Range.Text
strBody = "In striving to provide the best information possible to our associates, we ask you to please take five minutes to fill out this questionnaire and Email the completed form to: MKLLosscontrolQQ@markelcorp.com"
strTo = ""
If ActiveDocument.Fullname = "" Then
MsgBox "activedocument not saved, exiting"
Exit Sub
Else
If MsgBox("Activedocument NOT saved, Proceed?", vbYesNo, "Error") <> vbYes Then Exit Sub
End If
strAtt = ActiveDocument.Fullname
Set olkApp = CreateObject("outlook.application")
With olkApp.createitem(0)
.to = strTo
.Subject = strSubject
.body = strBody
.attachments.Add strAtt
'.send
.Display
End With
Set olkApp = Nothing
End Sub