Invoke a method on Word thread

G

Guest

How do I invoke a Word method on Words' thread, instead of on my app's thread?

Background:

My VB.NET app automates Word (2000 and onwards). After I do some editing
(successfully) on a Word.Document object, I then call the document object's
Save method, but it produces the following COMException: "The Save method or
property is not available because this document is in another application."

I have had numerous similiar COMExceptions when my Word event handlers (in
my app) attempt to call methods in my app. The way in which I resolved these
exceptions was modify these calls to invoke my app's methods via a delegate
using the Control.Invoke method. I understand this runs my app's methods on
my app's thread instead of on the Word thread. But this time, I figure I need
to do the opposite (run a Word method on a Word thread) - but how do I do
this since there is no Invoke method available on any of the Word objects?

Thanks in advance for your help!
 
G

Guest

I worked out the problem...it turned out that a control had open a document
(opened first) at the same time I was automating another document. So three
technical reasons combine to cause the Save method not to run:
1) Some Word commands, including Save cannot be run from inside another
application (see http://word.mvps.org/FAQs/MacrosVBA/IsWdDocInAnotherApp.htm)
2) Only one instance of Word was being used for both documents
3) The control started the instance
 

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