当前位置: 代码迷 >> VBA >> 实时异常'91'对象变量或with块变量未设置
  详细解决方案

实时异常'91'对象变量或with块变量未设置

热度:8958   发布时间:2013-02-26 00:00:00.0
实时错误'91'对象变量或with块变量未设置
我用VB 6.0开发一个示例ACTIVEX DLL 动态库,有一个过程

VB code
Sub ListFileInfo()    Dim xlapp As Object    Dim fso As New FileSystemObject    Dim fil As File    Dim fld As Folder    Dim i As Integer    Dim sh As New Worksheet        Set xlapp = GetObject(, "Excel.Application")    i = 1    Set fld = fso.GetFolder("c:\")    Set sh = xlapp.Worksheets("sheet1")    With sh        .Cells(i, 1) = "文件名"        .Cells(i, 2) = "文件大小"        .Cells(i, 3) = "最后修改时间"                i = i + 1        For Each fil In fld.Files            .Cells(i, 1) = fil.Name            .Cells(i, 2) = fil.Size            .Cells(i, 3) = fil.DateLastModified            i = i + 1        Next        .Range("a1").CurrentRegion.Columns.AutoFit    End WithEnd Sub



WFileListInfo.dll


然后我在Excel VBA工程中引用这个DLL,
代码如下:

VB code
Sub testCustomActiveX()    Dim myDll As clsFile    myDll.ListFileInfoEnd Sub


一开始进行几次还行,不过后来总出现如题的问题,不知道是怎么回事哦


------解决方案--------------------------------------------------------
注意要有 New 
VBScript code
Sub testCustomActiveX()    Dim myDll As New ClsFile    myDll.ListFileInfoEnd Sub
  相关解决方案