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 / Programming / October 2005

Tip: Looking for answers? Try searching our database.

mailmerge field problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Iacovou - 31 Oct 2005 05:45 GMT
hi there

i used the word macro recorder to get the basic code to mail merge a letter
with excel data - its my first day fiddling with word vba.
the macro links to the data source ok. If i toggle the "merge data" button,
it correctly replaces fields on screen with data from the excel worksheet.
what is odd is that if i .printpreview or .printout the page, even when it
displays the correct info, i get {MERGEFIELD SURNAME} etc etc. If i merge to
new document, then it replaces most of the information (except embedded date
field) - but seems a bit odd that it doesn't work directly...

Code snippet:

ActiveDocument.MailMerge.OpenDataSource Name:=thefile _
       , 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="" & thefile & "";Mode=Read;Extended Properties=""HDR=NO;IMEX=1;"";Jet
OLEDB:System database="""";Jet OLED" _
       , SQLStatement:="SELECT * FROM `Mailmerge$`", SQLStatement1:="",
SubType _
       :=wdMergeSubTypeAccess
   With ActiveDocument.MailMerge
       .Destination = wdSendToPrinter
       .SuppressBlankLines = True
       With .DataSource
           .FirstRecord = 1
           .LastRecord = 10
       End With
       .Execute Pause:=False
   End With

// end

"thefile" is the full path of the excel workbook.

comments / code etc greatly appreciated.
cheers

mike
Graham Mayor - 31 Oct 2005 06:55 GMT
Tools > options > print > uncheck 'field codes'.
Embedded date field?

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> hi there
>
[quoted text clipped - 41 lines]
>
> mike
Mike Iacovou - 31 Oct 2005 07:30 GMT
thanks. appreciate the quick response. seems to have done the job. :)

> Tools > options > print > uncheck 'field codes'.
> Embedded date field?
[quoted text clipped - 44 lines]
> >
> > mike

Rate this thread:






 
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.