Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with Word.Quit() from VB.NET

Status
Not open for further replies.

capitano

Programmer
Jul 30, 2001
88
US
I'm just learning to program MS-Word from VB.NET and getting errors when I try to call the quit() command. Can someone help? I'm following the examples in the book Mastering VisualBasic.NET as well as a Microsoft book on VB.NET. I'm doing this:

Dim WordApp As New Word.Application()
Dim newDoc As New Word.Document()
newDoc = WordApp.Documents.Add
newDoc.SaveAs("MyVBWordDoc")

...do stuff....

WordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
WordApp.Quit()

I get a blue squiggle under WordApp.Quit() with an error saying:
"Quit is ambiguous across the inherited interfaces 'Word._Application'and
'Word.ApplicationEvents2_Event'"

What does that mean and what should I do about it? I'm a little miffed because I'm just following the example code out of the book and it's not working.

Thanks for any help,
Bryan
 
So I guess there are 2 Quit() methods -- one for Word.Application and one for Word.ApplicationEvents2_Event. I think the problem is the compiler doesn't know which Quit method to invoke.

Has anybody seen this problem before or know what to do? Thanks a bunch,

Bryan
 
It turns out some changes just moments before the final release of VB.NET made this change:

Instead of:
Dim WordApp As New Word.Application()

It should actually be:
Dim WordApp As New Word._Application()

Now when you call WordApp.Quit(), it will actually quit without complaining.

Just thought I should pass on this tidbit for others.

Bryan
 
Bryan,
I am developing some similiar code and the same problem. But when I try to declare WordApp as New Word._Application is tells me that "New cannot be used on an interface".

My problem is that I need to close the instance of the document and application. Document.close does not work either

Thanks

Simon FAZTECH
:p
 
Simon,

Try doing it without declaring it as 'New' in the first line. This hunk of code works for me:

Dim WordApp As Word._Application
WordApp = New Word.Application()

'...create documents if you want:
Dim myDoc As New Word.Document()
myDoc = WordApp.Documents.Add

'...and so on as usual.

I had to really fiddle with Microsoft's Word programming API (within the VB.NET environment) to really get anything working. I think too many last minute changes on their part, as well as not-so-abundant documentation. I scoured several large-name bookstores, probably looking through over 100 texts and only found 2 which went through some basics on Word programming in the new VB.NET. And even then, some critical omissions (like the Word._Application) really put a wrench in my spokes. I've spend a lot of time the last 2 months getting familiar and comfortable with VB.NET ---> MS-Word programming. I run a web development business and am working on a content management system right now which downloads XML from a web database and converts the XML into MS-Word files. Whew!!! It's a beast of a programming project, but has forced me to get comfortable with VB.NET in a hurry! So, if you need any help, feel free to ask.

Ciao,
Bryan
 
Thanks Bryan,
That works great. Thanks for the help. If I ever have anymore troubles I contact you.

Thanks Again

Simon FAZTECH
:p
 
Bryan,

I tried it the way you explained but still it wouldn't work.
When if write the following lines:

Dim oWord As Word._Application()
oWord = New Word.Application()

the second line gives me the following error:
"Value of type 'Word.applicationClass' cannot be converted into '1-dimensional array of Word._Application'."

Does anybody have any other ideas or suggestions??

Ronny
 
Ronny,
Take the brackets () away from word._Application as it does not have a constructor. This line just sets oWord as type Application. Because there is no constructor, when putting brackets on the end, .net thinks you are declaring an array. So it should look like this

Dim oWord As Word._Application
oWord = New Word.Application()

Good luck

Simon
FAZTECH
:p
 
Hey Guys thanks for all these messages cause i was also having the same problem of the ambiguous interfaces.
Thanx a bilion Bryan. U are just great.

Ur "Dim wdApp As Word._Application" statement worked. However i am having one more problem while executing the statemebt
wdApp.Quit


It gives me error as following:

"The remote procedure call failed and did not execute. "
Nilesh Sawant.

I thought may be this is something to do with the DCom settings so i tried my hands over (dcomcnfg) but did not work.

Can anyone help me in this matter..???

Bryan.... Ur turn again.
 
Hey Guys thanks for all these messages cause i was also having the same problem of the ambiguous interfaces.
Thanx a bilion Bryan. U are just great.

Ur "Dim wdApp As Word._Application" statement worked. However i am having one more problem while executing the statemebt
wdApp.Quit


It gives me error as following:

"The remote procedure call failed and did not execute. "

I thought may be this is something to do with the DCom settings so i tried my hands over (dcomcnfg) but did not work.

Can anyone help me in this matter..???

Bryan.... Ur turn again.


By
Nilesh Sawant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top