Can not automation word with Vb.net

C

Cheng

Hi all,
Currently I am using vb.net to do automation. But I get an error message as
following:

Unable to cast COM object of type "System._Comobject' to interface type
'Microsoft.office.interop.word.application'. This operarion failed because
the QueryInterface call on the Com component for the interface with IID
'{00020970-0000-0000-C000-000000000046}' failed dude the following error:
Library not registered. (exception from HRESULT
0x8002801D(TYPE_E_LIBNOTREGISTERED)).


Testing Senario:

1.Test enviroment: Windows XP Pro. SP2, Office 2007,Reference
Microsoft.Office.Interop.Word, which is on a server (version 10)

(only office library version 12 in GAC , location C:\Windows\Assembly on
local PC not server)

The program runs smoothly, no error.


2.Test enviromen Windows XP Pro. SP2, office 2003, Reference
Microsoft.Office.Interop.Word, which is on a server (version 10)
(library version 11 and 12 in GAC , location C:\Windows\Assembly on local
PC not server)

Acction 1: Test in this enviroment: got an error : unable to cast from COM
word.applicationclass to interface type word._application (can not remember
all details)
Acction 2: Remove library version 12 from taget pc only keep version 11
results is the error I posted


Codes cause error:

Dim oApp as new Word.Application
oApp = CreateObject("Word.Application")

What shall I do to make this work on the second pc and what might cause this
problem?
 
C

Cindy M.

Hi Cheng,

The problem comes from a conflict between versions in the compiled code and on
the machines. If you program against the Office 2003 (11.0) version, then move
to a machine with Office 2007, things should work because the Office 2007 PIA
will automatically re-map to itself when it detects a call for an Office 2003
library. But going in the opposite direction will NOT work.
Currently I am using vb.net to do automation. But I get an error message as
following:

Unable to cast COM object of type "System._Comobject' to interface type
'Microsoft.office.interop.word.application'. This operarion failed because
the QueryInterface call on the Com component for the interface with IID
'{00020970-0000-0000-C000-000000000046}' failed dude the following error:
Library not registered. (exception from HRESULT
0x8002801D(TYPE_E_LIBNOTREGISTERED)).


Testing Senario:

1.Test enviroment: Windows XP Pro. SP2, Office 2007,Reference
Microsoft.Office.Interop.Word, which is on a server (version 10)

(only office library version 12 in GAC , location C:\Windows\Assembly on
local PC not server)

The program runs smoothly, no error.


2.Test enviromen Windows XP Pro. SP2, office 2003, Reference
Microsoft.Office.Interop.Word, which is on a server (version 10)
(library version 11 and 12 in GAC , location C:\Windows\Assembly on local
PC not server)

Acction 1: Test in this enviroment: got an error : unable to cast from COM
word.applicationclass to interface type word._application (can not remember
all details)
Acction 2: Remove library version 12 from taget pc only keep version 11
results is the error I posted


Codes cause error:

Dim oApp as new Word.Application
oApp = CreateObject("Word.Application")

What shall I do to make this work on the second pc and what might cause this
problem?


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 :)
 
C

Cheng

Hi Cindy,

Thanks for your reply. I did developed it on a office 2007 installed pc,
but the reference I used is Microsoft.Office.Interop.Word version 10 (which
is on a server). I dont know why , but it seems that when the program is run
on a office 2003 installed pc, it tried to use the assembly which is on local
drive.

Do you have any solution for that? I already switch the copy to local option
off for the referenc.

best regards,

Cheng
 
C

Cheng

Hi All,

I solved problem this morning. the problem is caused by incomplete register
in OS. There is 1 entry for word library 2007 on the target workstation,
after deleting that key, everything goes smoothly with 2003.


Thanks all.
 
J

Jason

I am receiving this error and I only have office 2000 installed on my
development machine. My references are pointing to Word and Office 9.0 Object
library only.

Is there a way to search for the a registry entry for a library causing this
error?


Jason
 

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