Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Applications / Word / February 2007



Tip: Looking for answers? Try searching our database.

Email Merge with First Name in body & Subject

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cleokolo@comcast.net - 23 Feb 2007 04:24 GMT
I'm trying to send a group of people an email.  I personalize the
email with each person's name.  Now I want to personalize the subject
line as well to each person.  For example:

Word email merge using the merge field names:

Dear Susan  (firstname)
Dear Jake  (firstname)
Dear Sam
Dear Joe

email merge

My subject would be  FirstName, Did you like the pictures I sent to
you (example).

Is there a way to include that merge field into the subject line?  Or
do I have to continue to open each one up and manually type in the
person's name in each email.  It get's old when you want to
personalize 20 or 30 or 50 emails.

Thank you.
Peter Jamieson - 23 Feb 2007 17:30 GMT
> Is there a way to include that merge field into the subject line?

As far as I know, only using VBA or another method of automating Word.

In Word 2002/2003 on Windows there are Merge Events which allow you to
change the .MailSubject attribute of the MailMerge object prior to merging
each record. Those Events don't exist on Word Mac as far as I know, but you
may be able to use VBA (or, say Applescript if that's your thing) to do one
merge per record in the data source. I have only used the following macro on
the Windows version so do not know if it will, or can, work on Mac. Also, it
will only work if you are producing one e-mail per record in your data
source. using stuff such as <<Next record>> fields will screw it up.

Sub ProduceOneEmailPerSourceRec()
'

' NB, needs bettor error management and doubtless other things a VBA expert
' will point out.

Dim intSourceRecord
Dim objMerge As Word.MailMerge
Dim bTerminateMerge As Boolean

' Need to set up this object as the ActiveDocument changes when the
' merge is performed. Besides, it's clearer.

Set objMerge = ActiveDocument.MailMerge
With objMerge

' If no data source has been defined, do it here using OpenDataSource.
' But if it is already defined in the document, you should not need to
define it here.

'  .OpenDataSource _
'    Name:="whatever"

' I don't use FirstRecord, LastRecord because they do not behave

' the way you expect in all data sources.

 intSourceRecord = 1
 bTerminateMerge = False

 Do Until bTerminateMerge
   .DataSource.ActiveRecord = intSourceRecord

   ' if we have gone past the end (and possibly, if there are no records)
   ' then the Activerecord will not be what we have just tried to set it to

   If .DataSource.ActiveRecord <> intSourceRecord Then
     bTerminateMerge = True
   ' the record exists
   Else

     .DataSource.FirstRecord = intSourceRecord
     .DataSource.LastRecord = intSourceRecord
     .Destination = = wdSendToEmail
     ' set up the field containing the e-mail address
     .MailAddressFieldName = "eaddress"
     ' Set up the subject - make sure any field name in here has the same

     ' capitalisaiton as the name in the data source
     .MailSubject = .DataSource.DataFields("FirstName").Value & _

                            "- did you like the pictures I sent to you?"
     .Execute

     intSourceRecord = intSourceRecord + 1
   End If
 Loop
End With

Peter Jamieson

> I'm trying to send a group of people an email.  I personalize the
> email with each person's name.  Now I want to personalize the subject
[quoted text clipped - 18 lines]
>
> Thank you.
John McGhie [MVP - Word and Word Macintosh] - 24 Feb 2007 06:10 GMT
Hi Peter:

Very nice indeed :-)  I fixed a couple of typos (below) and have tested that
it compiles on the Mac in Word 2004.  Given that all of the objects are
present in Word 2004 VBA, it should have a very high chance of working as
designed :-)

I am sure the questioner knows (because he has got this far) that Merge to
Email can be performed ONLY to Microsoft Entourage, which means Entourage
must be set as the default email program on the Mac.

On 24/2/07 4:30 AM, in article OHUwkA3VHHA.3592@TK2MSFTNGP03.phx.gbl, "Peter
Jamieson" <pjj@KillmapSpjjnet.demon.co.uk> wrote:

>> Is there a way to include that merge field into the subject line?
>
[quoted text clipped - 8 lines]
> will only work if you are producing one e-mail per record in your data
> source. using stuff such as <<Next record>> fields will screw it up.

Sub ProduceOneEmailPerSourceRec()
'

' NB, needs bettor error management and doubtless other things a VBA expert
' will point out.

Dim intSourceRecord
Dim objMerge As Word.MailMerge
Dim bTerminateMerge As Boolean

' If no data source has been defined, do it here using OpenDataSource.
' But if it is already defined in the document, you should not need to
define it here.

'  .OpenDataSource _
'    Name:="whatever"

' Need to set up this object as the ActiveDocument changes when the
' merge is performed. Besides, it's clearer.

Set objMerge = ActiveDocument.MailMerge
With objMerge

' I don't use FirstRecord, LastRecord because they do not behave
' the way you expect in all data sources.

 intSourceRecord = 1
 bTerminateMerge = False

 Do Until bTerminateMerge
   .DataSource.ActiveRecord = intSourceRecord

   ' if we have gone past the end (and possibly, if there are no records)
   ' then the Activerecord will not be what we have just tried to set it to

   If .DataSource.ActiveRecord <> intSourceRecord Then
     bTerminateMerge = True
   ' the record exists
   Else

     .DataSource.FirstRecord = intSourceRecord
     .DataSource.LastRecord = intSourceRecord
     .Destination = wdSendToEmail
     ' set up the field containing the e-mail address
     .MailAddressFieldName = "eaddress"
     ' Set up the subject - make sure any field name in here has the same
     ' capitalisaiton as the name in the data source
     
     .MailSubject = .DataSource.DataFields("FirstName").Value & _
                            "- did you like the pictures I sent to you?"
     .Execute
     intSourceRecord = intSourceRecord + 1
   End If
 Loop
End With
End Sub

Signature

Please reply to the newsgroup to maintain the thread.  Please do not email
me unless I ask you to.

John McGhie <john@mcghie.name>
Microsoft MVP, Word and Word for Macintosh.  Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410

Peter Jamieson - 24 Feb 2007 07:49 GMT
Re: Email Merge with First Name in body & SubjectJohn,

Thanks for giving that a once-over. At some point perhaps we'll find out whether the questioner is actually using a Mac :-)

Peter Jamieson

 Hi Peter:

 Very nice indeed :-)  I fixed a couple of typos (below) and have tested that it compiles on the Mac in Word 2004.  Given that all of the objects are present in Word 2004 VBA, it should have a very high chance of working as designed :-)

 I am sure the questioner knows (because he has got this far) that Merge to Email can be performed ONLY to Microsoft Entourage, which means Entourage must be set as the default email program on the Mac.

 On 24/2/07 4:30 AM, in article OHUwkA3VHHA.3592@TK2MSFTNGP03.phx.gbl, "Peter Jamieson" <pjj@KillmapSpjjnet.demon.co.uk> wrote:

 >> Is there a way to include that merge field into the subject line?
 >
 > As far as I know, only using VBA or another method of automating Word.
 >
 > In Word 2002/2003 on Windows there are Merge Events which allow you to
 > change the .MailSubject attribute of the MailMerge object prior to merging
 > each record. Those Events don't exist on Word Mac as far as I know, but you
 > may be able to use VBA (or, say Applescript if that's your thing) to do one
 > merge per record in the data source. I have only used the following macro on
 > the Windows version so do not know if it will, or can, work on Mac. Also, it
 > will only work if you are producing one e-mail per record in your data
 > source. using stuff such as <<Next record>> fields will screw it up.
 >
 Sub ProduceOneEmailPerSourceRec()
 '

 ' NB, needs bettor error management and doubtless other things a VBA expert
 ' will point out.

 Dim intSourceRecord
 Dim objMerge As Word.MailMerge
 Dim bTerminateMerge As Boolean

 ' If no data source has been defined, do it here using OpenDataSource.
 ' But if it is already defined in the document, you should not need to define it here.

 '  .OpenDataSource _
 '    Name:="whatever"

 ' Need to set up this object as the ActiveDocument changes when the
 ' merge is performed. Besides, it's clearer.

 Set objMerge = ActiveDocument.MailMerge
 With objMerge

 ' I don't use FirstRecord, LastRecord because they do not behave
 ' the way you expect in all data sources.

   intSourceRecord = 1
   bTerminateMerge = False

   Do Until bTerminateMerge
     .DataSource.ActiveRecord = intSourceRecord

     ' if we have gone past the end (and possibly, if there are no records)
     ' then the Activerecord will not be what we have just tried to set it to

     If .DataSource.ActiveRecord <> intSourceRecord Then
       bTerminateMerge = True
     ' the record exists
     Else

       .DataSource.FirstRecord = intSourceRecord
       .DataSource.LastRecord = intSourceRecord
       .Destination = wdSendToEmail
       ' set up the field containing the e-mail address
       .MailAddressFieldName = "eaddress"
       ' Set up the subject - make sure any field name in here has the same
       ' capitalisaiton as the name in the data source
       
       .MailSubject = .DataSource.DataFields("FirstName").Value & _
                              "- did you like the pictures I sent to you?"
       .Execute
       intSourceRecord = intSourceRecord + 1
     End If
   Loop
 End With
 End Sub

 --

 Please reply to the newsgroup to maintain the thread.  Please do not email me unless I ask you to.

 John McGhie <john@mcghie.name>
 Microsoft MVP, Word and Word for Macintosh.  Business Analyst, Consultant Technical Writer.
 Sydney, Australia +61 (0) 4 1209 1410
John McGhie [MVP - Word and Word Macintosh] - 24 Feb 2007 12:04 GMT
Nah, that would make it too easy :-)  He posted from an Intel Mac, if that's
any help :-)

On 24/2/07 6:49 PM, in article #57klg#VHHA.3980@TK2MSFTNGP02.phx.gbl, "Peter
Jamieson" <pjj@KillmapSpjjnet.demon.co.uk> wrote:

> Re: Email Merge with First Name in body & SubjectJohn,
>
[quoted text clipped - 96 lines]
> Technical Writer.
>   Sydney, Australia +61 (0) 4 1209 1410

Signature

Please reply to the newsgroup to maintain the thread.  Please do not email
me unless I ask you to.

John McGhie <john@mcghie.name>
Microsoft MVP, Word and Word for Macintosh.  Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410

Peter Jamieson - 24 Feb 2007 12:24 GMT
Re: Email Merge with First Name in body & SubjectUnfortunately, now I've been able to experiment, Activedocument.Mailmerge.Execute crashes Mac Word. Period. I suppose it's possible that that is "by design" to prevent automated mass mailings.

Also interesting that the UI lets you pick HTML or plain text (or attachment)  (as on Windows Word) but VBA on Mac does not support the .MailFormat property that lets you choose programmatically.

The other general way to approach this problem is to do one merge per record, merging to a new document then sending that via some automated method. However AFAIK .SendMail just opens a dialog rather than doing the sending and I don't know what other facilities for automating Entourage exist.

 John,

 Thanks for giving that a once-over. At some point perhaps we'll find out whether the questioner is actually using a Mac :-)

 Peter Jamieson

   "John McGhie [MVP - Word and Word Macintosh]" <john@mcghie.name> wrote in message news:C2062218.63A0B%john@mcghie.name...
   Hi Peter:

   Very nice indeed :-)  I fixed a couple of typos (below) and have tested that it compiles on the Mac in Word 2004.  Given that all of the objects are present in Word 2004 VBA, it should have a very high chance of working as designed :-)

   I am sure the questioner knows (because he has got this far) that Merge to Email can be performed ONLY to Microsoft Entourage, which means Entourage must be set as the default email program on the Mac.

   >> Is there a way to include that merge field into the subject line?
   >
   > As far as I know, only using VBA or another method of automating Word.
   >
   > In Word 2002/2003 on Windows there are Merge Events which allow you to
   > change the .MailSubject attribute of the MailMerge object prior to merging
   > each record. Those Events don't exist on Word Mac as far as I know, but you
   > may be able to use VBA (or, say Applescript if that's your thing) to do one
   > merge per record in the data source. I have only used the following macro on
   > the Windows version so do not know if it will, or can, work on Mac. Also, it
   > will only work if you are producing one e-mail per record in your data
   > source. using stuff such as <<Next record>> fields will screw it up.
   >
   Sub ProduceOneEmailPerSourceRec()
   '

   ' NB, needs bettor error management and doubtless other things a VBA expert
   ' will point out.

   Dim intSourceRecord
   Dim objMerge As Word.MailMerge
   Dim bTerminateMerge As Boolean

   ' If no data source has been defined, do it here using OpenDataSource.
   ' But if it is already defined in the document, you should not need to define it here.

   '  .OpenDataSource _
   '    Name:="whatever"

   ' Need to set up this object as the ActiveDocument changes when the
   ' merge is performed. Besides, it's clearer.

   Set objMerge = ActiveDocument.MailMerge
   With objMerge

   ' I don't use FirstRecord, LastRecord because they do not behave
   ' the way you expect in all data sources.

     intSourceRecord = 1
     bTerminateMerge = False

     Do Until bTerminateMerge
       .DataSource.ActiveRecord = intSourceRecord

       ' if we have gone past the end (and possibly, if there are no records)
       ' then the Activerecord will not be what we have just tried to set it to

       If .DataSource.ActiveRecord <> intSourceRecord Then
         bTerminateMerge = True
       ' the record exists
       Else

         .DataSource.FirstRecord = intSourceRecord
         .DataSource.LastRecord = intSourceRecord
         .Destination = wdSendToEmail
         ' set up the field containing the e-mail address
         .MailAddressFieldName = "eaddress"
         ' Set up the subject - make sure any field name in here has the same
         ' capitalisaiton as the name in the data source
         
         .MailSubject = .DataSource.DataFields("FirstName").Value & _
                                "- did you like the pictures I sent to you?"
         .Execute
         intSourceRecord = intSourceRecord + 1
       End If
     Loop
   End With
   End Sub

   --

   Please reply to the newsgroup to maintain the thread.  Please do not email me unless I ask you to.

   John McGhie <john@mcghie.name>
   Microsoft MVP, Word and Word for Macintosh.  Business Analyst, Consultant Technical Writer.
   Sydney, Australia +61 (0) 4 1209 1410
Jim Gordon MVP - 25 Feb 2007 01:01 GMT
Hi Peter,

I confirm that the execute command as used in your example causes Word to
crash. I tested Word 2004 and Word 2001. Both crashed.

After I made a slight modification, however, the code runs just fine.  I
think you can choose the format of the outgoing message. Here goes:

Sub ProduceOneEmailPerSourceRec()
'

' NB, needs bettor error management and doubtless other things a VBA expert
' will point out.

Dim intSourceRecord
Dim objMerge As Word.MailMerge
Dim bTerminateMerge As Boolean

' If no data source has been defined, do it here using OpenDataSource.
' But if it is already defined in the document, you should not need to
define it here.

'  .OpenDataSource _
'    Name:="whatever"

' Need to set up this object as the ActiveDocument changes when the
' merge is performed. Besides, it's clearer.

Set objMerge = ActiveDocument.MailMerge
With objMerge

' I don't use FirstRecord, LastRecord because they do not behave
' the way you expect in all data sources.

 intSourceRecord = 1
 bTerminateMerge = False

 Do Until bTerminateMerge
   .DataSource.ActiveRecord = intSourceRecord

   ' if we have gone past the end (and possibly, if there are no records)
   ' then the Activerecord will not be what we have just tried to set it to

   If .DataSource.ActiveRecord <> intSourceRecord Then
     bTerminateMerge = True
   ' the record exists
   Else

     objMerge.DataSource.FirstRecord = intSourceRecord
     objMerge.DataSource.LastRecord = intSourceRecord
     'objMerge.Destination = wdSendToEmail
     ' set up the field containing the e-mail address
     objMerge.MailAddressFieldName = "eaddress"
     ' Set up the subject - make sure any field name in here has the same
     ' capitalisaiton as the name in the data source
     
   With ActiveDocument.MailMerge
       .Destination = wdSendToEmail
       .Execute
   End With
   WordBasic.DMMMergeToEMail DMMEMailSendAs:=2, DMMEMailTo:=2,
DMMEMailSubject:=.DataSource.DataFields("First").Value & _
                            "- did you like the pictures I sent to you?"
     
     'objMerge.MailSubject = .DataSource.DataFields("First").Value & _
                            "- did you like the pictures I sent to you?"
     'objMerge.Execute
     intSourceRecord = intSourceRecord + 1
   End If
 Loop
End With
End Sub

Sub test()
Set MyMerge = ActiveDocument.MailMerge
If MyMerge.State = wdMainAndDataSource Then MyMerge.Execute

End Sub

-Jim Gordon
Mac MVP

Quoting from "Peter Jamieson" <pjj@KillmapSpjjnet.demon.co.uk>, in article
OXWlI6AWHHA.1208@TK2MSFTNGP03.phx.gbl, on [DATE:

> Unfortunately, now I've been able to experiment,
> Activedocument.Mailmerge.Execute crashes Mac Word. Period. I suppose it's
[quoted text clipped - 116 lines]
>>> End With
>>> End Sub

Signature

Jim Gordon
Mac MVP

MVPs are not Microsoft Employees
MVP info http://mvp.support.microsoft.com/

Peter Jamieson - 25 Feb 2007 12:24 GMT
Re: Email Merge with First Name in body & SubjectJim,

Thanks! Good old WordBasic, eh? I think they've even added stuff to the WordBasic object in Word 2007.

Peter Jamieson
 Hi Peter,

 I confirm that the execute command as used in your example causes Word to crash. I tested Word 2004 and Word 2001. Both crashed.

 After I made a slight modification, however, the code runs just fine.  I think you can choose the format of the outgoing message. Here goes:

 Sub ProduceOneEmailPerSourceRec()
 '

 ' NB, needs bettor error management and doubtless other things a VBA expert
 ' will point out.

 Dim intSourceRecord
 Dim objMerge As Word.MailMerge
 Dim bTerminateMerge As Boolean

 ' If no data source has been defined, do it here using OpenDataSource.
 ' But if it is already defined in the document, you should not need to define it here.

 '  .OpenDataSource _
 '    Name:="whatever"

 ' Need to set up this object as the ActiveDocument changes when the
 ' merge is performed. Besides, it's clearer.

 Set objMerge = ActiveDocument.MailMerge
 With objMerge

 ' I don't use FirstRecord, LastRecord because they do not behave
 ' the way you expect in all data sources.

   intSourceRecord = 1
   bTerminateMerge = False

   Do Until bTerminateMerge
     .DataSource.ActiveRecord = intSourceRecord

     ' if we have gone past the end (and possibly, if there are no records)
     ' then the Activerecord will not be what we have just tried to set it to

     If .DataSource.ActiveRecord <> intSourceRecord Then
       bTerminateMerge = True
     ' the record exists
     Else

       objMerge.DataSource.FirstRecord = intSourceRecord
       objMerge.DataSource.LastRecord = intSourceRecord
       'objMerge.Destination = wdSendToEmail
       ' set up the field containing the e-mail address
       objMerge.MailAddressFieldName = "eaddress"
       ' Set up the subject - make sure any field name in here has the same
       ' capitalisaiton as the name in the data source
       
     With ActiveDocument.MailMerge
         .Destination = wdSendToEmail
         .Execute
     End With
     WordBasic.DMMMergeToEMail DMMEMailSendAs:=2, DMMEMailTo:=2, DMMEMailSubject:=.DataSource.DataFields("First").Value & _
                              "- did you like the pictures I sent to you?"
       
       'objMerge.MailSubject = .DataSource.DataFields("First").Value & _
                              "- did you like the pictures I sent to you?"
       'objMerge.Execute
       intSourceRecord = intSourceRecord + 1
     End If
   Loop
 End With
 End Sub

 Sub test()
 Set MyMerge = ActiveDocument.MailMerge
 If MyMerge.State = wdMainAndDataSource Then MyMerge.Execute

 End Sub

 -Jim Gordon
 Mac MVP

 Quoting from "Peter Jamieson" <pjj@KillmapSpjjnet.demon.co.uk>, in article OXWlI6AWHHA.1208@TK2MSFTNGP03.phx.gbl, on [DATE:

   Unfortunately, now I've been able to experiment, Activedocument.Mailmerge.Execute crashes Mac Word. Period. I suppose it's possible that that is "by design" to prevent automated mass mailings.

   Also interesting that the UI lets you pick HTML or plain text (or attachment)  (as on Windows Word) but VBA on Mac does not support the .MailFormat property that lets you choose programmatically.

   The other general way to approach this problem is to do one merge per record, merging to a new document then sending that via some automated method. However AFAIK .SendMail just opens a dialog rather than doing the sending and I don't know what other facilities for automating Entourage exist.

    Peter Jamieson

   "Peter Jamieson" <pjj@KillmapSpjjnet.demon.co.uk> wrote in message news:%2357klg%23VHHA.3980@TK2MSFTNGP02.phx.gbl...

     John,

     
     
     Thanks for giving that a once-over. At some point  perhaps we'll find out whether the questioner is actually using a Mac  :-)

     
     
     Peter Jamieson

     
     

       "John McGhie [MVP - Word and Word Macintosh]" <john@mcghie.name> wrote in message news:C2062218.63A0B%john@mcghie.name...
       Hi  Peter:

       Very nice indeed :-)  I fixed a couple of typos (below)  and have tested that it compiles on the Mac in Word 2004.  Given that  all of the objects are present in Word 2004 VBA, it should have a very high  chance of working as designed :-)

       I am sure the questioner knows  (because he has got this far) that Merge to Email can be performed ONLY to  Microsoft Entourage, which means Entourage must be set as the default email  program on the Mac.

       On 24/2/07 4:30 AM, in article  OHUwkA3VHHA.3592@TK2MSFTNGP03.phx.gbl, "Peter Jamieson"  <pjj@KillmapSpjjnet.demon.co.uk> wrote:

       >> Is there a way to include that merge field into the  subject line?
       >
       > As far as I know,  only using VBA or another method of automating Word.
       >
       > In  Word 2002/2003 on Windows there are Merge Events which allow you to
       >  change the .MailSubject attribute of the MailMerge object prior to merging  
       > each record. Those Events don't exist on Word Mac as far as I know,  but you
       > may be able to use VBA (or, say Applescript if that's your  thing) to do one
       > merge per record in the data source. I have only  used the following macro on
       > the Windows version so do not know if  it will, or can, work on Mac. Also, it
       > will only work if you are  producing one e-mail per record in your data
       > source. using stuff  such as <<Next record>> fields will screw it up.
       >  
       Sub ProduceOneEmailPerSourceRec()
       '

       ' NB, needs bettor  error management and doubtless other things a VBA expert
       ' will point  out.

       Dim intSourceRecord
       Dim objMerge As Word.MailMerge
       Dim  bTerminateMerge As Boolean

       ' If no data source has been defined, do  it here using OpenDataSource.
       ' But if it is already defined in the  document, you should not need to define it here.

       '   .OpenDataSource _
       '    Name:="whatever"

       '  Need to set up this object as the ActiveDocument changes when the
       ' merge  is performed. Besides, it's clearer.

       Set objMerge =  ActiveDocument.MailMerge
       With objMerge

       ' I don't use FirstRecord,  LastRecord because they do not behave
       ' the way you expect in all data  sources.

         intSourceRecord =  1
         bTerminateMerge = False

         Do Until  bTerminateMerge
           .DataSource.ActiveRecord =  intSourceRecord

           ' if we have gone past  the end (and possibly, if there are no records)
           '  then the Activerecord will not be what we have just tried to set it  to

           If .DataSource.ActiveRecord <>  intSourceRecord Then
             bTerminateMerge  = True
           ' the record  exists
           Else

             .DataSource.FirstRecord  =  intSourceRecord
             .DataSource.LastRecord  = intSourceRecord
             .Destination =  wdSendToEmail
             ' set up the field  containing the e-mail  address
             .MailAddressFieldName =  "eaddress"
             ' Set up the subject -  make sure any field name in here has the  same
             ' capitalisaiton as the name in  the data  source
             
             .MailSubject  = .DataSource.DataFields("FirstName").Value &  _
                                    "-  did you like the pictures I sent to  you?"
             .Execute
             intSourceRecord  = intSourceRecord + 1
           End  If
         Loop
       End With
       End Sub

 --
 Jim Gordon
 Mac MVP

 MVPs are not Microsoft Employees
 MVP info http://mvp.support.microsoft.com/
Jim Gordon MVP - 25 Feb 2007 15:58 GMT
Hi Peter,

Office 2004 is the last version of Office that will support Visual Basic for
Applications directly. In the future you¹ll need to run VBA via a compiled
executive file such as AppleScript or RealBasic.

-Jim

Quoting from "Peter Jamieson" <pjj@KillmapSpjjnet.demon.co.uk>, in article
OO9kmeNWHHA.480@TK2MSFTNGP02.phx.gbl, on [DATE:

> Jim,
>  
[quoted text clipped - 230 lines]
>> MVPs are not Microsoft Employees
>> MVP info  http://mvp.support.microsoft.com/

Signature

Jim Gordon
Mac MVP

MVPs are not Microsoft Employees
MVP info http://mvp.support.microsoft.com/

Peter Jamieson - 25 Feb 2007 18:29 GMT
Re: Email Merge with First Name in body & SubjectHi Jim,

Yes, I hope the various things that rely on WordBasic will still be do-able in the next release.

Peter Jamieson
 Hi Peter,

 Office 2004 is the last version of Office that will support Visual Basic for Applications directly. In the future you'll need to run VBA via a compiled executive file such as AppleScript or RealBasic.

 -Jim

 Quoting from "Peter Jamieson" <pjj@KillmapSpjjnet.demon.co.uk>, in article OO9kmeNWHHA.480@TK2MSFTNGP02.phx.gbl, on [DATE:

   Jim,

   Thanks! Good old WordBasic, eh? I think they've even added stuff to the WordBasic object in Word 2007.

   Peter Jamieson

     "Jim Gordon MVP" <goldkey74@WarmerThanWarmMail.com>  wrote in message news:C2064A26.171AC%goldkey74@WarmerThanWarmMail.com...
     Hi  Peter,

     I confirm that the execute command as used in your example  causes Word to crash. I tested Word 2004 and Word 2001. Both  crashed.

     After I made a slight modification, however, the code runs  just fine.  I think you can choose the format of the outgoing message.  Here goes:

     Sub ProduceOneEmailPerSourceRec()
     '

     ' NB, needs  bettor error management and doubtless other things a VBA expert
     ' will  point out.

     Dim intSourceRecord
     Dim objMerge As  Word.MailMerge
     Dim bTerminateMerge As Boolean

     ' If no data source  has been defined, do it here using OpenDataSource.
     ' But if it is already  defined in the document, you should not need to define it here.

     '   .OpenDataSource _
     '    Name:="whatever"

     ' Need  to set up this object as the ActiveDocument changes when the
     ' merge is  performed. Besides, it's clearer.

     Set objMerge =  ActiveDocument.MailMerge
     With objMerge

     ' I don't use FirstRecord,  LastRecord because they do not behave
     ' the way you expect in all data  sources.

       intSourceRecord = 1
       bTerminateMerge  = False

       Do Until  bTerminateMerge
         .DataSource.ActiveRecord =  intSourceRecord

         ' if we have gone past the  end (and possibly, if there are no records)
         ' then  the Activerecord will not be what we have just tried to set it  to

         If .DataSource.ActiveRecord <>  intSourceRecord Then
           bTerminateMerge =  True
         ' the record  exists
         Else

           objMerge.DataSource.FirstRecord  =  intSourceRecord
           objMerge.DataSource.LastRecord  = intSourceRecord
           'objMerge.Destination  = wdSendToEmail
           ' set up the field  containing the e-mail  address
           objMerge.MailAddressFieldName =  "eaddress"
           ' Set up the subject - make  sure any field name in here has the  same
           ' capitalisaiton as the name in  the data  source
           
         With  ActiveDocument.MailMerge
             .Destination  =  wdSendToEmail
             .Execute
         End  With
         WordBasic.DMMMergeToEMail DMMEMailSendAs:=2,  DMMEMailTo:=2, DMMEMailSubject:=.DataSource.DataFields("First").Value &  _
                                  "-  did you like the pictures I sent to  you?"
           
           'objMerge.MailSubject  = .DataSource.DataFields("First").Value &  _
                                  "-  did you like the pictures I sent to  you?"
           'objMerge.Execute
           intSourceRecord  = intSourceRecord + 1
         End  If
       Loop
     End With
     End Sub

     Sub test()
     Set MyMerge  = ActiveDocument.MailMerge
     If MyMerge.State = wdMainAndDataSource Then  MyMerge.Execute

     End Sub

     -Jim Gordon
     Mac  MVP

     Quoting from "Peter Jamieson"  <pjj@KillmapSpjjnet.demon.co.uk>, in article  OXWlI6AWHHA.1208@TK2MSFTNGP03.phx.gbl, on [DATE:

     

       Unfortunately,  now I've been able to experiment, Activedocument.Mailmerge.Execute crashes  Mac Word. Period. I suppose it's possible that that is "by design" to  prevent automated mass mailings.

       Also  interesting that the UI lets you pick HTML or plain text (or attachment)   (as on Windows Word) but VBA on Mac does not support the .MailFormat  property that lets you choose programmatically.

       The other  general way to approach this problem is to do one merge per record, merging  to a new document then sending that via some automated method. However AFAIK  .SendMail just opens a dialog rather than doing the sending and I don't know  what other facilities for automating Entourage exist.

        Peter  Jamieson

       "Peter  Jamieson" <pjj@KillmapSpjjnet.demon.co.uk> wrote in message  news:%2357klg%23VHHA.3980@TK2MSFTNGP02.phx.gbl...
       

         John,

         
         
         Thanks for giving that a once-over. At some point  perhaps  we'll find out whether the questioner is actually using a Mac   :-)

         
         
         Peter Jamieson

         
         
         

           "John McGhie [MVP - Word and Word  Macintosh]" <john@mcghie.name> wrote in message  news:C2062218.63A0B%john@mcghie.name...
           Hi  Peter:

           Very nice indeed :-)   I fixed a couple of typos (below)  and have tested that it  compiles on the Mac in Word 2004.  Given that  all of the  objects are present in Word 2004 VBA, it should have a very high   chance of working as designed :-)

           I am sure the questioner  knows  (because he has got this far) that Merge to Email can be  performed ONLY to  Microsoft Entourage, which means Entourage must  be set as the default email  program on the Mac.

           On 24/2/07  4:30 AM, in article  OHUwkA3VHHA.3592@TK2MSFTNGP03.phx.gbl, "Peter  Jamieson"  <pjj@KillmapSpjjnet.demon.co.uk>  wrote:

           >> Is there a way to include  that merge field into the  subject line?
           >
           > As far as I know,  only using VBA or  another method of automating Word.
           >
           > In  Word  2002/2003 on Windows there are Merge Events which allow you to
           >   change the .MailSubject attribute of the MailMerge object prior to  merging  
           > each record. Those Events don't exist on Word Mac  as far as I know,  but you
           > may be able to use VBA (or, say  Applescript if that's your  thing) to do one
           > merge per  record in the data source. I have only  used the following macro on  
           > the Windows version so do not know if  it will, or can,  work on Mac. Also, it
           > will only work if you are  producing  one e-mail per record in your data
           > source. using stuff   such as <<Next record>> fields will screw it  up.
           >  
           Sub  ProduceOneEmailPerSourceRec()
           '

           ' NB, needs bettor  error  management and doubtless other things a VBA expert
           ' will point   out.

           Dim intSourceRecord
           Dim objMerge As  Word.MailMerge
           Dim  bTerminateMerge As Boolean

           ' If no  data source has been defined, do  it here using  OpenDataSource.
           ' But if it is already defined in the  document,  you should not need to define it here.

           '    .OpenDataSource _
           '     Name:="whatever"

           '  Need to set up this  object as the ActiveDocument changes when the
           ' merge  is  performed. Besides, it's clearer.

           Set objMerge =   ActiveDocument.MailMerge
           With objMerge

           ' I don't use  FirstRecord,  LastRecord because they do not behave
           ' the way  you expect in all data  sources.

             intSourceRecord  =  1
             bTerminateMerge = False

             Do  Until   bTerminateMerge
               .DataSource.ActiveRecord  =  intSourceRecord

               ' if we have  gone past  the end (and possibly, if there are no  records)
               '  then the Activerecord will  not be what we have just tried to set it   to

               If .DataSource.ActiveRecord  <>  intSourceRecord  Then
                 bTerminateMerge  =  True
               ' the record   exists
               Else

                 .DataSource.FirstRecord   =   intSourceRecord
                 .DataSource.LastRecord   =  intSourceRecord
                 .Destination =   wdSendToEmail
                 ' set up the  field  containing the e-mail   address
                 .MailAddressFieldName  =  "eaddress"
                 ' Set up the  subject -  make sure any field name in here has the   same
                 ' capitalisaiton as  the name in  the data   source
                 
                 .MailSubject   = .DataSource.DataFields("FirstName").Value &   _
                                        "-   did you like the pictures I sent to   you?"
                 .Execute
                 intSourceRecord   = intSourceRecord + 1
               End   If
             Loop
           End With
           End  Sub

     --  
     Jim Gordon
     Mac MVP

     MVPs are not Microsoft Employees
     MVP info  http://mvp.support.microsoft.com/

 --
 Jim Gordon
 Mac MVP

 MVPs are not Microsoft Employees
 MVP info http://mvp.support.microsoft.com/
Jim Gordon MVP - 27 Feb 2007 04:13 GMT
If my understanding is correct (based on Word¹s help file) WordBasic is not
compiled. It¹s just a collection of about 900 commands. Since it is not
compiled there is at least a chance it will survive the upgrade.

-Jim Gordon
Mac MVP

Quoting from "Peter Jamieson" <pjj@KillmapSpjjnet.demon.co.uk>, in article
O2arFrQWHHA.388@TK2MSFTNGP04.phx.gbl, on [DATE:

> Hi Jim,
>  
[quoted text clipped - 272 lines]
>> MVPs are not Microsoft Employees
>> MVP info  http://mvp.support.microsoft.com/

Signature

Jim Gordon
Mac MVP

MVPs are not Microsoft Employees
MVP info http://mvp.support.microsoft.com/

Peter Jamieson - 28 Feb 2007 09:01 GMT
Re: Email Merge with First Name in body & SubjectI don't know how WordBasic is implemented on either platform but on the Windows side it's presented as an Object that's a property of the Global/Application objects, and about which the Object Browser holds no further info. It's not clear whether every WordBasic command that manipulates Word actually invokes Word's COM object (or however it works on Mac) and that the reason why some WordBasic commands (such as the ones we're talking about) are not available in VBA is simply because they have not been exposed via the object library or some such. Nor is it completely clear /why/ some of these things have been implemented via Wordbasic rather than the published object model - perhaps it's precisely to avoid publishing a new interface because the longterm plan is not to have those objects, or maybe it's to circumvent some security problem or other.

In order to be able to use the WordBasic stuff I assume that the next version of (Mac) Word is either going to need to
a. provide access to the WordBasic object (I don't see that facility in the AppleScript dictionary at the moment, for example, but perhaps it is there). In addition, any language using that object would have to be syntactically capable of doing so. Or
b. provide direct access to the objects that WordBasic is using. At the moment I don't see that in AppleScript either in this case, but perhaps it's there somewhere.

Otherwise MS would be saying "you won't be able to automate that any more", and of course they may have their reasons for doing that too.

My own experience is that any developer including MS is quite capable of forgetting this kind of stuff until very late in the development day so I only mention it because I hear that the MacBU is watching :-)

Peter Jamieson

 If my understanding is correct (based on Word's help file) WordBasic is not compiled. It's just a collection of about 900 commands. Since it is not compiled there is at least a chance it will survive the upgrade.

 -Jim Gordon
 Mac MVP

 Quoting from "Peter Jamieson" <pjj@KillmapSpjjnet.demon.co.uk>, in article O2arFrQWHHA.388@TK2MSFTNGP04.phx.gbl, on [DATE:

   Hi Jim,

   Yes, I hope the various things that rely on WordBasic will still be do-able in the next release.

   Peter Jamieson

     "Jim Gordon MVP" <goldkey74@WarmerThanWarmMail.com>  wrote in message news:C2071C4A.17263%goldkey74@WarmerThanWarmMail.com...
     Hi  Peter,

     Office 2004 is the last version of Office that will support  Visual Basic for Applications directly. In the future you'll need to run VBA  via a compiled executive file such as AppleScript or  RealBasic.

     -Jim

     Quoting from "Peter Jamieson"  <pjj@KillmapSpjjnet.demon.co.uk>, in article  OO9kmeNWHHA.480@TK2MSFTNGP02.phx.gbl, on [DATE:

     

       Jim,

       Thanks! Good  old WordBasic, eh? I think they've even added stuff to the WordBasic object  in Word 2007.

       Peter  Jamieson

         "Jim Gordon MVP"  <goldkey74@WarmerThanWarmMail.com>  wrote in message  news:C2064A26.171AC%goldkey74@WarmerThanWarmMail.com...
         Hi   Peter,

         I confirm that the execute command as used in your  example  causes Word to crash. I tested Word 2004 and Word 2001. Both   crashed.

         After I made a slight modification, however, the  code runs  just fine.  I think you can choose the format of the  outgoing message.  Here goes:

         Sub  ProduceOneEmailPerSourceRec()
         '

         ' NB, needs  bettor error  management and doubtless other things a VBA expert
         ' will  point  out.

         Dim intSourceRecord
         Dim objMerge As   Word.MailMerge
         Dim bTerminateMerge As Boolean

         ' If no data  source  has been defined, do it here using OpenDataSource.
         ' But  if it is already  defined in the document, you should not need to  define it here.

         '   .OpenDataSource _
         '     Name:="whatever"

         ' Need  to set up this  object as the ActiveDocument changes when the
         ' merge is   performed. Besides, it's clearer.

         Set objMerge =   ActiveDocument.MailMerge
         With objMerge

         ' I don't use  FirstRecord,  LastRecord because they do not behave
         ' the way you  expect in all data  sources.

           intSourceRecord =  1
           bTerminateMerge  = False

           Do Until   bTerminateMerge
             .DataSource.ActiveRecord  =  intSourceRecord

             ' if we have  gone past the  end (and possibly, if there are no  records)
             ' then  the Activerecord will not  be what we have just tried to set it   to

             If .DataSource.ActiveRecord  <>  intSourceRecord  Then
               bTerminateMerge =   True
             ' the record   exists
             Else

               objMerge.DataSource.FirstRecord   =   intSourceRecord
               objMerge.DataSource.LastRecord   =  intSourceRecord
               'objMerge.Destination   = wdSendToEmail
               ' set up the  field  containing the e-mail   address
               objMerge.MailAddressFieldName  =  "eaddress"
               ' Set up the  subject - make  sure any field name in here has the   same
               ' capitalisaiton as the  name in  the data   source
               
             With   ActiveDocument.MailMerge
                 .Destination   =   wdSendToEmail
                 .Execute
             End   With
             WordBasic.DMMMergeToEMail  DMMEMailSendAs:=2,  DMMEMailTo:=2,  DMMEMailSubject:=.DataSource.DataFields("First").Value &   _
                                      "-   did you like the pictures I sent to   you?"
               
               'objMerge.MailSubject   = .DataSource.DataFields("First").Value &   _
                                      "-   did you like the pictures I sent to   you?"
               'objMerge.Execute
               intSourceRecord   = intSourceRecord + 1
             End   If
           Loop
         End With
         End Sub

         Sub  test()
         Set MyMerge  = ActiveDocument.MailMerge
         If MyMerge.State  = wdMainAndDataSource Then  MyMerge.Execute

         End  Sub

         -Jim Gordon
         Mac  MVP

         Quoting from "Peter  Jamieson"  <pjj@KillmapSpjjnet.demon.co.uk>, in article   OXWlI6AWHHA.1208@TK2MSFTNGP03.phx.gbl, on  [DATE:

         
         

           Unfortunately,  now I've been able to experiment,  Activedocument.Mailmerge.Execute crashes  Mac Word. Period. I  suppose it's possible that that is "by design" to  prevent  automated mass mailings.

           Also   interesting that the UI lets you pick HTML or plain text (or  attachment)   (as on Windows Word) but VBA on Mac does not  support the .MailFormat  property that lets you choose  programmatically.

           The other   general way to approach this problem is to do one merge per  record, merging  to a new document then sending that via some  automated method. However AFAIK  .SendMail just opens a dialog  rather than doing the sending and I don't know  what other  facilities for automating Entourage exist.

            Peter   Jamieson

           "Peter  Jamieson"  <pjj@KillmapSpjjnet.demon.co.uk> wrote in message   news:%2357klg%23VHHA.3980@TK2MSFTNGP02.phx.gbl...
           
           

             John,

             
             
             Thanks for giving that a once-over. At some point   perhaps  we'll find out whether the questioner is actually  using a Mac   :-)

             
             
             Peter Jamieson

             
             
             
             

               "John McGhie [MVP - Word and  Word  Macintosh]" <john@mcghie.name> wrote in message   news:C2062218.63A0B%john@mcghie.name...
               Hi  Peter:

               Very nice indeed :-)    I fixed a couple of typos (below)  and have tested  that it  compiles on the Mac in Word 2004.  Given that   all of the  objects are present in Word 2004 VBA, it  should have a very high   chance of working as designed  :-)

               I am sure the questioner  knows  (because he  has got this far) that Merge to Email can be  performed ONLY to   Microsoft Entourage, which means Entourage must  be set  as the default email  program on the Mac.

               On 24/2/07   4:30 AM, in article   OHUwkA3VHHA.3592@TK2MSFTNGP03.phx.gbl, "Peter  Jamieson"   <pjj@KillmapSpjjnet.demon.co.uk>   wrote:

               >> Is there a way to  include  that merge field into the  subject  line?
               >
               > As far as I know,   only using VBA or  another method of automating  Word.
               >
               > In  Word  2002/2003 on Windows  there are Merge Events which allow you to
               >    change the .MailSubject attribute of the MailMerge  object prior to  merging  
               > each record. Those  Events don't exist on Word Mac  as far as I know,  but you  
               > may be able to use VBA (or, say  Applescript if that's  your  thing) to do one
               > merge per  record in the  data source. I have only  used the following macro on  
               > the Windows version so do not know if  it will,  or can,  work on Mac. Also, it
               > will only work if you  are  producing  one e-mail per record in your data  
               > source. using stuff   such as <<Next  record>> fields will screw it  up.
               >  
               Sub   ProduceOneEmailPerSourceRec()
               '

               ' NB, needs bettor   error  management and doubtless other things a VBA  expert
               ' will point   out.

               Dim  intSourceRecord
               Dim objMerge As  Word.MailMerge
               Dim   bTerminateMerge As Boolean

               ' If no  data source  has been defined, do  it here using  OpenDataSource.
               '  But if it is already defined in the  document,  you should  not need to define it here.

               '     .OpenDataSource _
               '      Name:="whatever"

               '  Need to set  up this  object as the ActiveDocument changes when the
               '  merge  is  performed. Besides, it's clearer.

               Set  objMerge =   ActiveDocument.MailMerge
               With  objMerge

               ' I don't use  FirstRecord,  LastRecord  because they do not behave
               ' the way  you expect in all data   sources.

                 intSourceRecord  =   1
                 bTerminateMerge = False

                 Do   Until    bTerminateMerge
                   .DataSource.ActiveRecord   =  intSourceRecord

                   '  if we have  gone past  the end (and possibly, if there are  no  records)
                   '  then the  Activerecord will  not be what we have just tried to set it    to

                   If  .DataSource.ActiveRecord  <>  intSourceRecord   Then
                     bTerminateMerge   =  True
                   ' the record    exists
                   Else

                     .DataSource.FirstRecord    =    intSourceRecord
                     .DataSource.LastRecord    =   intSourceRecord
                     .Destination  =   wdSendToEmail
                     '  set up the  field  containing the e-mail    address
                     .MailAddressFieldName   =  "eaddress"
                     '  Set up the  subject -  make sure any field name in here  has the   same
                     '  capitalisaiton as  the name in  the data    source
                     
                     .MailSubject    = .DataSource.DataFields("FirstName").Value &    _
                                            "-    did you like the pictures I sent to    you?"
                     .Execute
                     intSourceRecord    = intSourceRecord + 1
                   End    If
                 Loop
               End With
               End   Sub

         --  
         Jim Gordon
         Mac MVP

         MVPs are  not Microsoft Employees
         MVP info  http://mvp.support.microsoft.com/

     --  
     Jim Gordon
     Mac MVP

     MVPs are not Microsoft Employees
     MVP info  http://mvp.support.microsoft.com/

 --
 Jim Gordon
 Mac MVP

 MVPs are not Microsoft Employees
 MVP info http://mvp.support.microsoft.com/
Daiya Mitchell - 25 Feb 2007 18:27 GMT
side note--whenever I've gotten messages with my first name in the
subject line, they've been spam.  Not sure your plan is worth the effort.

> I'm trying to send a group of people an email.  I personalize the
> email with each person's name.  Now I want to personalize the subject
[quoted text clipped - 18 lines]
>
> Thank you.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.