Returning to Main Document

R

Roderick O'Regan

Here's the scenario...

The main document based on a template has been set up with the merge
fields and letter body text written.

A database has been opened.

A VBA procedure carries out the merge to a new document.

The merged document now takes the focus i.e. it becomes the active
document.

This is fine as I have to programatically carry out some actions in
this active document.

Is there a way, please, to now programatically return to the main
merge document?

This main document might not have been saved so I cannot refer to it
by name.

Regards

Roderick
 
P

Peter Jamieson

The main document based on a template has been set up with the merge
fields and letter body text written.

As long as your code can make a reference to the document at this point, the
reference is still valid after the merge has been completed.

If your code cannot do that, then your code would ultimately have to guess,
I think.

Peter Jamieson
 
R

Roderick O'Regan

Thanks Peter for the tip.

Using the VBA help and your advice I've cobbled together something
like this below:
======================
Sub FindMergeMainDoc()
For Each docloop In Documents
With docloop
If .Bookmarks.Exists("MainMergeDoc") Then
Documents(docloop).MailMerge.EditMainDocument
Exit Sub
End If
End With
Next docloop
End Sub
=======================

It loops through all the open documents correctly and recognises the
bookmark in the Main Merge Document but it doesn't make it the active
document by bringing it to the fore.

Any ideas, please, where I'm going wrong?

Regards

Roderick
 
D

Doug Robbins - Word MVP

I assume that the VBA procedure that executes the merge is run when the mail
merge main document is the Active Document. In that case, in your present
VBA procedure, declare an object as a Document then at the beginning of the
code set that object to the then active document, then at the end of the
present code, issue a command to activate the document.
Sub whateveritisnow()
Dim mmmdoc as Document
Set mmmdoc = ActiveDocument

[rest of your code]

mmmdoc.Activate
End Sub
--
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