Link to home
Start Free TrialLog in
Avatar of aetheon
aetheonFlag for United States of America

asked on

System.InvalidCastException on create Excel.Application obj after installing Office XP PIA

Hi,

Im writing a VB.Net app that automates Excel 2000.  I found the Office xp interop and installed it on my machine (note: I do not have office xp) oxppia.exe.  So after installing this, now I find that my app throws a System.InvalidCastException error on this line of code:

xlApp = CType(CreateObject("Excel.Application"), Excel.Application)

Which had been working for days before I installed the interop.  In hindsite, I guess maybe it was dumb to install the interop when I dont
have Office xp, but I couldnt clearly discearn that it would not work with office 2000.

Ive got the idea, that my gac is messed up now, I tried to uninstall the interop assemblies that I had just added into the gac,
but only 2 of the 4 would uninstall.
Office and StdOle would not allow removal.  ( I was using gacutil /u, and tried gacutil /uf)

Any help would be most welcome.
Avatar of Dranizz
Dranizz

test if it's created

dim obj as object

obj = CreateObject("Excel.Application"),

if obj.gettype is typeof(excel.application) then
Avatar of aetheon

ASKER

oooh found a good clue, I clicked on Excel under References in the Solution Explorer and it shows:
Name  Interop.Excel
Desc   Microsoft Excel 9.0 Object Library

That aint right?  I think I need to figure out how to re-install that dll
ok then you can instaiate it corectly as
Dim obj as new Excel.Application
Avatar of aetheon

ASKER

umm, yeah I can instantiat it as an obj.  And Excel as an application itself works fine.
I wonder if its some registry setting that now points to the wrong dll.
I still think it could be a gac thing.
that might not work because Excel.Application will always refer to the latest version of Excel.
Therefore, when you install Office XP PIA, it might update Excel.Application to Excel.Application.10

Why don't you try it with

xlApp = CType(CreateObject("Excel.Application.9"), Excel.Application)

it might work....
You can also try to revert it back by saving the following text with .REG extension and just run it.


-------------------------------
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Excel.Application\CurVer]
@="Excel.Application.9"
-------------------------------

and then get your fingers cross and try to run your own application again.

Avatar of aetheon

ASKER

good thinking testn, I thought you might be on to something, but, turns out that ::
   xlApp = CType(CreateObject("Excel.Application.9"), Excel.Application)
      didnt help, same invalid cast

  I ran regedit and manually found the key HKEY_CLASSES_ROOT\Excel.Application\CurVer
      and saw that the value was = Excel.Application.9
Avatar of aetheon

ASKER

In Visual Studio - I opened the object browser, and pointed to the 'Application' object under Excel
then grabbed the GUID from the description,
looked up the GUID in the registry {000208D5-0000-0000-C000-000000000046}
and found the key TypeLib = {00020813-0000-0000-C000-000000000046}

Then, I found that value as a key under the key TypeLib and deleted the '1.4' key under that
which pointed to 10.0 Excel Interop

That fixed it!   -guess I get the points : )


Avatar of Bob Learned
One, thing, though is that you are mixing early-bound and late-bound:

xlApp = New Excel.Application is all you need.
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: Dranizz {http:#9923244} & testn {http:#9924016} & TheLearnedOne {http:#9928104}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
Avatar of aetheon

ASKER

I thank everyone for their input, however none of the comments provided a solution.
All of the comments were helpful from the standpoint of inspiring me to look in places
I may not have thought of on my own, especially the one from testn regarding the values
in the registry.
Avatar of aetheon

ASKER

I wanted to give 50 points to testn, but apparently that isnt possible,
so I will not give any points, and I wont accept an answer, cuz the best
by far was the one I found on my own.  This can be closed out in my opinion.
Thanx.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial