Why can't VB.net find the class name using GetObject

1.7k views Asked by At

This is a follow-up to my previous Question about GetObject This code:

Dim wb As Object ' Lotus123.Document
wb = GetObject("S:\Temp\T\0375D.WK3", "Lotus123.Workbook")

Works fine in VBA but fails in VB.net with the error: FileNotFoundException: "File name or class name not found during Automation operation."

I checked out the process with Process Monitor and found: Both VBA and VB.net check these keys:

HKCR\Lotus123.Workbook\CLSID\(Default)
HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}
HKCU\Software\Classes

Then VB.net simply stops

But VBA keeps on going with these keys

HKLM\SOFTWARE\Microsoft\COM3\REGDBVersion
HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}\InprocServer32    NAME NOT FOUND
HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}\InprocServerX86   NAME NOT FOUND
HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}\InprocServer32    NAME NOT FOUND
HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}\InprocServerX86   NAME NOT FOUND
HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}\LocalServer32 SUCCESS
HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}\LocalServer32\(Default) SUCCESS 

The last one gives the reward: Data: c:\lotus\123\123w.exe And VBA goes on to open the 123w.exe program with the specified file.

So why can't VB.net find the class name? I don't understand why it simply quits looking.

3

There are 3 answers

1
D_Bester On BEST ANSWER

There appears to be a mismatch between the file name (gets spreadsheet document) and Lotus123.Workbook which returns the parent of the application object.

The code below works in XP 32 bit as well as in Win8 64 bit. I checked with process monitor what is happening under the hood. CreateObject checks for the CLSID in the registry using the given object. Then it looks up the necessary info using the CLSID.

Public Shared Function GetLotusWB(ByVal sFile As String) As Object

    'HKCU takes precedence if exists
    'HKCU\Software\Classes\Lotus123.Workbook\CLSID
    'HKCU\Software\Classes\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}

    'normally this is used because Lotus123 doesn't create HKCU entries
    'HKCR\Lotus123.Workbook\CLSID = {29130007-2EED-1069-BF5D-00DD011186B7}
    'HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}\InprocHandler32 = ole32.dll
    'HKCR\CLSID\{29130007-2EED-1069-BF5D-00DD011186B7}\LocalServer32 = C:\Lotus\123\123w.exe

    'using object as that sometimes works better
    Dim LotusObj As Object = CreateObject("Lotus123.Workbook")

    'get application
    'need a reference to Lotus 123 else declare as Object
    Dim LotusApp As Lotus123.Application = LotusObj.Application
    'FAILS: LotusApp.Visible = True

    'open file; also works fine As Lotus123.Document
    Dim ldoc As Object = LotusApp.OpenDocument(sFile)

    'visible and activate (must declare as Object else gives exception)
    Dim appObject As Object = ldoc.Application 
    appObject.Visible = True
    ldoc.Activate()

    Return ldoc

End Function

In VB.net, this doesn't work Dim wb As Object: wb = GetObject(sFile, "Lotus123.Workbook") (worked in VBA)

In Win8 64bit this wb = GetObject(sFile) doesn't work; just hangs.

5
Jack Gajanan On

you need to install office api or PIA (Primary Interop Assemblies) to get this working

you can find PIA for office 2010 here http://www.microsoft.com/en-us/download/details.aspx?id=3508

find other versions by searching google

1
D_Bester On

For some reason VB.net cannot find the class name "Lotus123.Workbook" so I tried getting the file without the class name and it works fine.

Dim wb As Object ' Lotus123.Document
wb = GetObject("S:\Temp\T\0375D.WK3")