Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-22-2018, 04:45 PM
naeemakhtar naeemakhtar is offline Populating email subject from a MS-Word document Windows 10 Populating email subject from a MS-Word document Office 2016
Novice
Populating email subject from a MS-Word document
 
Join Date: Apr 2016
Posts: 8
naeemakhtar is on a distinguished road
Arrow 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
Reply With Quote
 

Tags
email, letter, ms-word



Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating email subject from a MS-Word document 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
Populating email subject from a MS-Word document run word doc when a email is received with a certain subject based on rules megatronixs Outlook 3 10-18-2014 11:47 AM
Populating email subject from a MS-Word document 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft