Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Returning to Main Document
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 |
#2
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Returning to Main Document
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 "Roderick O'Regan" wrote in message ... 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 |
#3
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Returning to Main Document
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 On Fri, 28 Jul 2006 02:50:57 +0100, "Peter Jamieson" wrote: 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 "Roderick O'Regan" wrote in message .. . 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 |
#4
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Returning to Main Document
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 "Roderick O'Regan" wrote in message ... 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 On Fri, 28 Jul 2006 02:50:57 +0100, "Peter Jamieson" wrote: 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 "Roderick O'Regan" wrote in message . .. 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 |
#5
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Returning to Main Document
Thank you Doug.
Worked a treat! Regards Roderick On Fri, 28 Jul 2006 19:25:49 +0200, "Doug Robbins - Word MVP" wrote: 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Once i have merged data into the main document how do i edit? | Mailmerge | |||
Document Type Problem | Mailmerge | |||
How to number only the Main Document, not first pages | Microsoft Word Help | |||
Data Files Not "Attached" to Mail Merge Main Document | Mailmerge | |||
How to protect the main document in a mail merge process | Mailmerge |