Why doesn't code work in VB.net, but works in VBA; GetObject

五迷三道 提交于 2019-12-02 02:11:10

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 in XP.

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

EDIT: In Win8 64bit the above doesn't work; just hangs.

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

This works great because it creates the "Lotus123.Workbook" which is used to get the application object.

Load the file into an Excel workbook. It should be able to convert the lotus123 workbook on the fly.

First of all, check to make sure your inclusions (I think under Tools menu, includes or references or something like that) include the library that references Lotus123.Document. Chances are it's in the "Microsoft Excel 14.0 Object Library" or similar.

I've heard it said that VB is not VBA!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!