Open copy of merge doc, close original without saving

T

Todd K.

I found the code to do this on another area of this newsgroup, but it doesn't
appear to work. I have entered the following in a Word module:
Public Sub DoMailMerge()

Dim DocName
DocName = ActiveDocument.Name
'Do mailmerge
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
'Close mailmerge document
Windows(DocName).Close wdDoNotSaveChanges

End Sub

Then in the Document_Open property of my mailmerge document, I wrote
DoMailMerge. But when I open the document (from Access), it just opens the
orginal merge document. No errors, no debug, no copy that I can see.
 
T

Todd K.

I have heard of this issue before, and I think at this point I am fine with
having the users click <Yes> at the prompt for letting the SQL run. Once we
click <Yes> though, shouldn't it run the code?
 
P

Peter Jamieson

Well, i just tried something like this and the SQL registry setting didn't
obviously make a difference. However, what does happen depends on the code
you're running in Access.

What happened on my system was that when I opened the document (from an
Access VBA routine), Word did open and execute the merge. Then your code
closes the mail merge main document. It's helpful to make Word visible
before opening the document so you can see what's happening. If you don't do
that, you won't see anything.

Anyway, after the macro runs, the result document is there in Word. However,
if you are running from an Access module that sets the Word object to
nothing or quits Word, chances are you will either be left with invisible
WINWORD processes in your Windows task list, or the output document will
just be deleted.

Peter Jamieson
 
T

Todd K.

The code I run in Access simply does a hyperlink to open up the Word document
(Application.FollowHyperlink "I:\Applications\Databases\Amendment_Ren.doc"),
it's the code below in the Word document that is supposed to open up a copy
and close the original. I guess I have two questions:

1) If I adjust the SQL registry setting, will it allow the code below to
operate in the Word document?
2) If not, what else could it be?
 
P

Peter Jamieson

OK, when I do it that way, the main thing that stops anything from happening
is when I set macro Security in Word to High, i.e. so Word simply won't run
the macros unless the conditions are right.

Peter Jamieson
 
T

Todd K.

Jamieson, you're a genius! I hadn't even thought about reducing security in
Word, once I did, the code worked perfectly.

Thanks!
 

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