这是发布与错误 91 相关的#12772920的延续。好的,情况就是这样。(1) 如果这一行被注释掉,那么 (2) 会产生错误 91。如果没有被注释掉,代码运行良好。(3) 这应该将公共 obj shCompanies 指向“公司”表,不是吗?我很困惑为什么这条线似乎没有像 (1) 那样设置 shCompanies 对象。
Option Explicit
Public wbCode As Workbook
Public Sub Main()
Dim tables As New CTables
Set wbCode = ThisWorkbook
Call SetExcelObjects
(2)Call tables.Indexing
End Sub
Public Sub SetExcelObjects()
Dim tables As New CTables
(3)Set tables.shCompanies = wbCode.Worksheets("Companies")
End Sub
---Class Module CTables
Option Explicit
Public shCompanies As Worksheet
Public Sub Indexing()
Dim rng As Long
Dim tables As New CTables
(1)Set tables.shCompanies = wbCode.Worksheets("Companies")
rng = tables.shCompanies.UsedRange.Rows.Count
End Sub