Mac 2011 Word - Mail Merge Dynamic subject line

Joined
Jun 28, 2015
Messages
2
Reaction score
0
Points
1
Trying to create dynamic subject line using VBA I found the following but its based on being applied to Windows:

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

Mail Merge - Dynamic subject line? - Access World Forums

I have tested this on Mac 2011 Word and it does not work. Anyone know how, or if the VBA needs modifying for Mac. Its beyond my VBA skills.
 

chscag

Well-known member
Staff member
Admin
Joined
Jan 23, 2008
Messages
65,248
Reaction score
1,833
Points
113
Location
Keller, Texas
Your Mac's Specs
2017 27" iMac, 10.5" iPad Pro, iPhone 8, iPhone 11, iPhone 12 Mini, Numerous iPods, Monterey
VBA macros designed to be used in Windows Word do not work when applied to Word on a Mac. You'll need to convert the Macro or use Apple Script. Good chance for you to learn VBA. ;D
 
OP
C
Joined
Jun 28, 2015
Messages
2
Reaction score
0
Points
1
Thanks chscag,

VBA macros designed to be used in Windows Word do not work when applied to Word on a Mac. You'll need to convert the Macro or use Apple Script.

Do you know of any good beginner guides, recommended reads for converting VBA macros from MS to AppleMac?
 

chscag

Well-known member
Staff member
Admin
Joined
Jan 23, 2008
Messages
65,248
Reaction score
1,833
Points
113
Location
Keller, Texas
Your Mac's Specs
2017 27" iMac, 10.5" iPad Pro, iPhone 8, iPhone 11, iPhone 12 Mini, Numerous iPods, Monterey
Hi:

The best document for learning purposes is here. Take note though that it's very comprehensive and large. You might want to wait to see what MS gives us in Office 2016. I'm currently testing Office 2016 (Preview) but haven't had a chance to play around with the new VBA. Supposedly it will be standard between versions.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top