mailmerge field problem

M

Mike Iacovou

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
 
G

Graham Mayor

Tools > options > print > uncheck 'field codes'.
Embedded date field?

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top