![]() |
|
#1
|
|||
|
|||
|
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 |
| Tags |
| email, letter, ms-word |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Adding document fields to subject line of email
|
russkris | Word VBA | 3 | 09-24-2017 08:18 PM |
| Populating a Word document with VBA\SQL | shabbaranks | Mail Merge | 23 | 07-21-2015 01:31 PM |
run word doc when a email is received with a certain subject based on rules
|
megatronixs | Outlook | 3 | 10-18-2014 11:47 AM |
Program to read Email subject line word by word
|
john23# | Outlook | 1 | 02-14-2014 10:21 PM |
| Lack of email addresses auto-populating | LarryK | Outlook | 0 | 10-10-2012 08:09 AM |