Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 05-04-2020, 05:52 AM
kuankailok kuankailok is offline VBA code to CC multiple people in mail merge by word Windows 10 VBA code to CC multiple people in mail merge by word Office 2016
Novice
VBA code to CC multiple people in mail merge by word
 
Join Date: Apr 2020
Posts: 2
kuankailok is on a distinguished road
Default

Code:
Dim WithEvents wdapp As Application

Dim EMAIL_SUBJECT As String

Dim FIRST_RECORD As Boolean





Private Sub Document_Open()



    Set wdapp = Application

    ThisDocument.MailMerge.ShowWizard 1

   

End Sub



Private Sub Document_Close()



    Set wdapp = Nothing

    

End Sub





Private Sub wdapp_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean)

    Dim i As Integer

    

    With ActiveDocument.MailMerge

    

        If FIRST_RECORD = True Then 

            EMAIL_SUBJECT = .MailSubject

            FIRST_RECORD = False

        Else .MailSubject = EMAIL_SUBJECT

        End If



        i = .DataSource.DataFields.Count

        

        Do While i > 0

            .MailSubject = Replace(.MailSubject, "<" & .DataSource.DataFields(i).Name & ">", .DataSource.DataFields(i).Value, , , vbTextCompare)

            i = i - 1

        Loop



    End With

    

     

End Sub





Private Sub wdapp_MailMergeBeforeMerge(ByVal Doc As Document, ByVal StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)



    FIRST_RECORD = True

    

End Sub



Private Sub wdapp_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult As Document)



    ActiveDocument.MailMerge.MailSubject = EMAIL_SUBJECT

     

End Sub
This is the code i'm using to obtain a dynamic subject, however, looks like i cannot put it in the right position? Could you please help?

Additionally, do i need to change anything in your provided code (as i saw there is a ".Cell(j,i)".

Thanks for your help anyway

*** if needed, i could put my sample doc here for your kind checking.... my purpose is to send out email by mail merge with a dynamic subject while copying the right personnel in each individual email, i know that's crazy but wanna complete this in a very short time....typing out each email takes time............

Last edited by kuankailok; 05-04-2020 at 05:54 AM. Reason: added some more comments
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA code to CC multiple people in mail merge by word Word Mail Merge Envelope Addresses with Multiple Conditions Pedro007 Mail Merge 2 11-19-2019 07:25 AM
VBA code to CC multiple people in mail merge by word Mail Merge Student Transcript - Multiple Years from multiple sheets aizah2018 Mail Merge 1 11-11-2018 01:27 AM
VBA code to CC multiple people in mail merge by word Mail Merge Code Issue Andrewwill Mail Merge 6 01-06-2018 10:25 PM
Mail Merge to multiple employees in multiple locations as PDF by location GFiz Mail Merge 1 05-13-2017 08:01 PM
VBA code to CC multiple people in mail merge by word Mail Merge Multiple Rows -word(from Spain) luisaranda Mail Merge 6 03-06-2016 09:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:31 PM.


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