function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ddoellingddoelling 

VBA script can't find open mail merge document

I am working on a contract generator that takes the output of the mail merge process and customizes it based on data extracted from Salesforce as well as options selected by the user.  The generator is simply a Word document that contains nothing but a couple of forms and VBA script.  We have stored the generator on the Documents tab (to manage change control).  The mail merge file contains bookmarked text that the generator uses to build the contract.  (Note:  I inherited this from a prototype someone created so I'm stuck with this design for now.)

The process for using the generator was that the user would run the mail merge (keeping the output displayed in IE) and then run the generator.   When the generator starts it finds all the open Word documents (Documents.Count) and loads a list box with the document names.  The problem is that the output of the mail merge isn't listed as a document in the list box.  I now understand that the file created out of the mail merge is just a view of a Word document running inside IE.  Word is not running as an application - IE is the application.  What I don't understand is why when I view the VBA file located in Documents, it starts and runs the VBA script in IE just like it was running as a Word application.  I'm not a MS developer type so maybe this is my ignorance.  

Is there a way that I could add code in the generator to obtain a list of all the open IE windows and load them into the list box?   I don't like the idea of requiring the user to save the mail merge document prior to running the generator.   

DevAngelDevAngel

Hi ddoelling,

Not sure I can help.  When ever I run a mail merge, the document is opened in a new instance of Word.  Would this work if the document was always opened outside of the browser?

If so, here is a link that tells you how to make sure it is not opened in the browser.

http://blogs.msdn.com/gusperez/archive/2004/04/28/122768.aspx

 

ddoellingddoelling

Seems that the problem is unpredictable.   I have been coding and testing all day and didn't have a problem until early this afternoon when I sort of "lost" the open file.  The output of the mail merge is still sitting in the same window on my desktop from this morning.  Look in Task Manager and there it is as a Word document but for some unknown reason the result of Documents.Count doesn't find it. 

There is a problem on Microsoft's support site regarding a problem in Word 2000 when using the Windows.Count command.  I am assuming that the problem is any Count command.   

I found a possible workaround on the MS Discussions Group Board involving parsing of Windows tasks.   I added the code and was succesful in finding the document.  I removed the " - Microsoft Word" from the task name but I got an error when the code tried to Activate that document.  So I guess my only option for now is to require the user to save the file.