Macro Problem With Merge

M

Matthew W

Hi
I've written a very simple find and replace macro, however when I merge a
document into the template, the macro runs BEFORE the merging (I tested this
with a msgbox that shows the macro has run beforehand). I am using "autonew"
for the macro at the moment but I really want it to wait until after the
merging to run.
Any ideas?

Thanks.
Matthew
 
D

Doug Robbins - Word MVP

Incorporate code in the macro to execute the merge and then have it perform
your find operation on the document that is created by executing the merge.

--
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
 
M

Matthew W

Hi
The problem is, is that the merge occurs via an Access VBA application so
the Word document is produced from that and then appears on the screen.
 
D

Doug Robbins - Word MVP

I don't know where the Autonew would come into it if the merge is being
performed via an Access application, but then I also can't imagine why you
would be wanting Find and Replace in these circumstances either.



You need to do something like:

Set wrdApp = CreateObject("Word.Application")
wrdApp.Documents.Open FileName:=strDoc, AddToRecentFiles:=False,
Visible:=True
wrdApp.Documents.Item(1).Activate
With wrdApp.Documents(strDoc).MailMerge
.DataSource.FirstRecord = 1
.DataSource.LastRecord = 1
.Destination = wdSendToNewDocument
.Execute
End With
With wrdApp.Documents.Item(1)
'Your find code
End With


--
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
 

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