I'm trying to automate MS Word 9 on Windows 2000 from VB.NET. I'm using the
following code:
Dim TmpltPath As String = Path.Combine(Application.StartupPath,
"SpanishForm.doc")
Dim pcss(), pcs As Process
Dim WDoc As Word.Document
Dim WApp As Word.Application
If Process.GetProcessesByName("WINWORD").Length = 0 Then
Process.Start(mstrWord)
Threading.Thread.Sleep(3000)
End If
WDoc = New Word.Document() <=== Interop COM Exception: Call was
rejected by callee.
WApp = WDoc.Application
WApp.Documents.Close(False)
WApp.Documents.Open(strDocPath)
but about 50% of the time, it errors out as indicated above. How can I
dependably instantiate a new Word.Document object without getting this
error? Thanks.
Jonathan West - 25 Aug 2006 08:25 GMT
> I'm trying to automate MS Word 9 on Windows 2000 from VB.NET. I'm using
> the
[quoted text clipped - 11 lines]
> WDoc = New Word.Document() <=== Interop COM Exception: Call was
> rejected by callee.
Try changing the line above to this
wDoc = WApp.Documents.Add()
> WApp = WDoc.Application
> WApp.Documents.Close(False)
[quoted text clipped - 3 lines]
> dependably instantiate a new Word.Document object without getting this
> error? Thanks.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Cindy M. - 25 Aug 2006 14:51 GMT
Hi Jonathan,
> Try changing the line above to this
>
> wDoc = WApp.Documents.Add()
That's going to be a bit difficult if he hasn't assigned
wdApp to a Word application instance, yet...
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)
Cindy M. - 25 Aug 2006 09:35 GMT
Hi Phil,
Do you have to use GetProcessByName rather than using Reflection and
GetActiveObject? The problem is, you really should assign the instance of Word
to an application object, then start the new document from there. Something
more like (off the top of my head, so possible syntax errors!)
Imports word = Microsoft.Office.Interop.Word
Imports marshal = System.Runtime.InteropServices.Marshal
Private MySub()
Dim wdApp as Word.Application =
CType(marshal.GetActiveObject("Word.Application"), word.Application)
'And if no Word app is running, then
'wdApp = New Word.Application
> I'm trying to automate MS Word 9 on Windows 2000 from VB.NET. I'm using the
> following code:
[quoted text clipped - 17 lines]
> dependably instantiate a new Word.Document object without getting this
> error?
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)