Log in

View Full Version : word document reference



neogeoIT
10-13-2010, 07:55 PM
I have created word.application object and document object and apply code to the document through Access, the code runs no problem.

However, when the code run for the second time while the first document still open, no matter what i try the code still reference to the first document but not the new create second document.

I tried to use document name, which i debug see the name is correct, or use the document object to ref, or use activedocument after using the .activate still no help.

set all objects to nothing, end the sub and run again, still not good.

anything i can do or is it a bug in office3 2010?

macropod
10-14-2010, 12:12 AM
Hi neogoIT,

It would help if you posted the code ...

Having said that, are you creating a new Word instance each time you run the code? If so, it's quite reasonable that the new instance won't see whatever's in another instance. So, if you need to access an already-open document, you need to avoid creating a new Word instance.

fumei
10-14-2010, 09:42 AM
Yes, posting your code will help.

macropod is likely correct. If you are executng the code the second time you are executing the SAME code as the first - thus getting the same result.

So, as macropod suggests, do a test for an existing instance of Word - use GetObject - and if there is none, make one. If there IS one, use that one rather than creating a new one.