Populating email subject from a MS-Word document
I have created a simple macro that will save a MS-Word document and email it to a designated user. I would like to create VBA that would capture the reference line in the MS-Word document and populate the subject of the email with this reference.
The MS-Word document is a letter. The first line is the date. The next three lines are the address. The fourth line is the reference.
March 22 2018
Mr. John Doe
123 Main Street
Anytown AN 11111
re: Microsoft matter (capture this information in subject heading email)
Please provide VBA code that will capture the contents in the reference section of the letter and populate the subject of the email with this information.
Below is the code for the save and send.
Sub sendeMail()
Dim olkApp As Object
Dim strSubject As String
Dim strTo As String
Dim strBody As String
Dim strAtt As String
strSubject = "Whatever!"
strBody = "Please see attached File"
strTo = "fred@fred.com"
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
|