Word Macro to create PDF then attach PDF to email with address from merged data

I cannot figure out how to put dynamic data from the SQL Server datasource to the Outlook email address field. I've got two days on this and so close.

CONTEXT: My ladies on the front desk email reservations to people. It's a rediculously slow process. Here is my VBA that is almost complete to make it where they just run macro and then hit send.

I can't get the email address with field name "GuestEMail" to the .To attribute. I do not know VBA but I've pieced together many macros to get this far. I know the organization of the code is atrocious.

SEE VIDEO for more understanding: https://goo.gl/YKqGq0

Sub PPMagic_MOVE_N_SAVE0()
    Selection.Copy
    ChangeFileOpenDirectory "C:\files\PPMagic\"
    ActiveDocument.SaveAs2 FileName:=Trim(Selection.Text) & ".doc", FileFormat _
        :=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
        True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
        False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=0

    Dim strData As String
    Dim strFileName As String
    
    strData = "C:\files\PPMagic\" & Trim(Selection.Text) & ".pdf"
    
    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        strData, ExportFormat:= _
        wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
        Item:=wdExportDocumentWithMarkup, IncludeDocProps:=False, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
        On Error Resume Next
        
strData = "C:\files\PPMagic\" & Trim(Selection.Text) & ".pdf"

Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object
Dim strEmail As String

Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments


With OutLookMailItem
    .To = GuestEMail
    .Subject = "Your James W. Smith Reservation"
    '.Body = "Thank you for booking with us. Here is your reservation." & vbNewLine & signature
    myAttachments.Add (strData)
    '.Send
    .Display
End With
    signature = OutLookMailItem.Body

Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
        
End Sub

Open in new window

commfirstAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try

.To = activedocument.MailMerge.DataSource.DataFields("GuestEMail").Value

Regards
commfirstAuthor Commented:
That didn't work. I'm googling and trying variations. I'll see if that will put the email in the body. Just thought of that.

Sorry for delay and thanks for your time.
commfirstAuthor Commented:
The connection was only being fed to an RTF and then the DOC file was created from that file. Thus I could not read the merge data. I hid it in the doc and searched range to place in variable.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
commfirstAuthor Commented:
I'm guessing I wasn't a good question writer. I figured it out on my own because no one helped. No biggy. I love figuring this stuff out. Just don't always have the time to do it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.