Good Morning All,
Firstly thanks to Gerry for more of his kind words, and to both Gerry and PH for picking up while I went out for a drink (and came back unfit to post), and thanks to PH for pointing out my repeated error about using Set with .Visible.
Now, Anita, Gerry is correct in that you should be using Templates (.dot files) instead of skeleton documents (.doc files) and you should follow PH's advice and make sure you properly qualify all Word objects with the Word Application (however I don't think you can have implicit instantiation by not doing this).
That aside your procedure doesn't seem to be particularly complex but I am confused about a couple of things. The process seems to involve prompting the user for some file names, opening and populating a Word document, and then giving the user the option to save and possibly presenting the user with the document for further editing.
1. I presume that there is something else going on (or why would you be doing this from Excel).
2. Why do you do all the work and then allow the user to throw it away?
Lastly, if you are allowing the user to edit the document after you have done, this could be causing some of your problems. My understanding of what happens is this:
- You instantiate Word from Excel and you maintain a pointer to it (
WordApp).
The Word object will exist as long as that pointer is maintained.
- You hand over the Word Application to your User. The User does what they want - and, then, presumably, closes Word (is this correct?)
- After the User has closed Word the Window is closed BUT the Word object remains in memory (and in the Task List) because you still have a pointer to it,
WordApp, in your code.
I would need to run some tests to confirm this but I offer it as possible explanation.
Enjoy,
Tony
--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[