Computing.Net > Forums > Programming > VB.NET and WORD

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VB.NET and WORD

Reply to Message Icon

Original Message
Name: VASS
Date: November 17, 2004 at 18:12:10 Pacific
Subject: VB.NET and WORD
OS: win xp sp2
CPU/Ram: 512
Comment:

I am trying to open a WORD document. Just one day ago it was working ok. Now i get the following:
QueryInterface for interface Word._Application failed.
at Word.ApplicationClass.set_Visible(Boolean prop)

when i am trying to open a word document. I have a reference to Word 8.0, and when I tryed to change it to reference a Word 11.0 (Office 2003) after the debug it wasn't working. I even restored my backup file with the word 8 reference and again i get the same error. I deleted the whole directory that i had the program on and restored from back up and nothing. I tryed in a WIn98 machine with Office 2002 and worked OK. What the heck is going on? Any help please. I am attaching my set of commands.

/===============================================
Dim i As Integer

Dim oWord As Word.ApplicationClass

oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Open(Application.StartupPath & "\stecr1.doc")
//===========================================


Report Offensive Message For Removal


Response Number 1
Name: konichi
Date: November 28, 2004 at 16:09:52 Pacific
Reply: (edit)

Late-binding is the only way to work with multiple versions of Word... Therefore don't use a reference at design time, late-binding will grab the reference at run-time.

If you're wondering what I'm going on with about "Late-binding" then read-on!

You've bascially got the premise by using the createobject command. And an example follows:

TURN OFF OPTION STRICT
-----------------------
Dim i As Integer

Dim oWord As OBJECT

oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Open(Application.StartupPath & "\stecr1.doc")

------------------

The only difference is the "Dim oWord As OBJECT" bit... because we're just telling .Net that it's going to be a reference to something there, and then we define the reference by using the CreateObject command

http://www.appliedlanguage.com


Report Offensive Follow Up For Removal

Response Number 2
Name: VASS
Date: November 29, 2004 at 20:09:28 Pacific
Reply: (edit)

Thank you Konichi. It worked. I just said dim oWord as Object and it worked like you said. Thank you again.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software