1

クラスオブジェクトが認識されないという問題があります(エラー91、オブジェクト参照が設定されていません)。コードは次のとおりです。

---Main (Standard Module)
Option Explicit
Public wbCode As Workbook

Public Sub MainSub()
Dim str As String
Dim tables As New CTables
Call SetExcelObjects
str = tables.shExclusions.Cells(20, 1) ---this produces error 91
End Sub

Public Sub SetExcelObjects()
Dim tables As New CTables
Dim str As String
Set wbCode = ThisWorkbook
Set tables.shExclusions = wbCode.Worksheets("Exclusions")
str = tables.shExclusions.Cells(20, 1) ---this line executes okay
End Sub


---CTables (Class Module)
Option Explicit
Public shExclusions As Worksheet
4

1 に答える 1

1

これを試して:

---Main (Standard Module) 
Option Explicit 
Public wbCode As Workbook 

Public Sub MainSub() 
Dim str As String 
Dim tables As New CTables 
Call SetExcelObjects(tables)
str = tables.shExclusions.Cells(20, 1) ---this produces error 91 
End Sub 

Public Sub SetExcelObjects(tables as CTables) 
Dim str As String 
Set wbCode = ThisWorkbook 
Set tables.shExclusions = wbCode.Worksheets("Exclusions") 
str = tables.shExclusions.Cells(20, 1) ---this line executes okay 
End Sub 


---CTables (Class Module) 
Option Explicit 
Public shExclusions As Worksheet 
于 2012-10-07T02:47:17.830 に答える