Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / July 2005

Tip: Looking for answers? Try searching our database.

[VBA]  how to automate the mail merge process?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Philippe Pons - 22 Jul 2005 09:30 GMT
Hello,

I would like to control mailmerge by code. Addresses are in an xl file.
I recorded the whole process with the macro recorder.
However, when I run the macro, I do get the four letters (4 addresses
selected in the sql statement)
but the addresses fields remain desperately blank!
If you could put me on thetrack to solve this, I would thank you!(4 days
since I'm trying to fix it!)
Philippe.

Here's the code snippet I got with the macro recorder:

Sub Publi4()
'
' Publi4 Macro
' Macro enregistrée le 22/07/2005 par Philippe Pons
'
   ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
   ActiveDocument.MailMerge.OpenDataSource Name:= _
       "F:\Documents and
Settings\Administrateur\Bureau\SAVATOU_Chambéry\Dossiers techniques\Essai
analyse Excel\Analyse de données3.xls" _
       , ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
       AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
_
       WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False,
_
       Format:=wdOpenFormatAuto, Connection:= _
       "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
Source=F:\Documents and
Settings\Administrateur\Bureau\SAVATOU_Chambéry\Dossiers techniques\Essai
analyse Excel\Analyse de données3.xls;Mode=Read;Extended
Properties=""HDR=YES;IMEX=1;"";Jet OLE" _
       , SQLStatement:="SELECT * FROM `'Adresses relances$'`WHERE coll_id
in (1, 2, 3, 4)", SQLStatement1:="" _
       , SubType:=wdMergeSubTypeAccess
   ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
       wdFieldAddressBlock, Text:= _
       "\f ""<<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>" & Chr(13) &
"<<_COMPANY_" & Chr(13) & ">><<_STREET1_" & Chr(13) & ">><<_STREET2_" &
Chr(13) & ">><<_POSTAL_>><< _CITY_>><<" & Chr(13) & "_STATE_>>"" \l 1036 \c
0 \e """""
   With ActiveDocument.MailMerge
       .Destination = wdSendToNewDocument
       .SuppressBlankLines = True
       With .DataSource
           .FirstRecord = wdDefaultFirstRecord
           .LastRecord = wdDefaultLastRecord
       End With
       .Execute Pause:=False
   End With
   ActiveWindow.ActivePane.VerticalPercentScrolled = 9
End Sub
Doug Robbins - 22 Jul 2005 12:56 GMT
Sorry, but it is crazy to try and create a mailmerge maindocument from
scratch using VBA.  Automate the attachment of the datasource and the
execution of the merge if you will, but in 4 days you could have done it
manually countless times over.

Also, I would suggest that you do not use the AddressBlock field (which is
probably the cause of your problem).  Far better to just insert the
individual fields in the configuration that you want them.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hello,
>
[quoted text clipped - 53 lines]
>    ActiveWindow.ActivePane.VerticalPercentScrolled = 9
> End Sub
Philippe Pons - 22 Jul 2005 13:17 GMT
Thanks Dough, will try follow your recomendations.
Philippe

> Sorry, but it is crazy to try and create a mailmerge maindocument from
> scratch using VBA.  Automate the attachment of the datasource and the
[quoted text clipped - 62 lines]
> >    ActiveWindow.ActivePane.VerticalPercentScrolled = 9
> > End Sub
 
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.