我正在编写一些VBA来检查单击按钮时电子表格的更改。电子表格在temp目录中创建自己的副本,由Workbook_Open()上的环境变量确定。这一切都运行正常,但问题出在我的button_click sub。
根据this问题的建议,我试图将感兴趣的范围读入数组。问题是,我的阵列是空的。我忘了在这里做些什么蠢事吗?
Dim wsOriginalWS As Worksheet
Dim varOriginalSheet As Variant
Dim wbkOrig As Workbook
Dim strRangeToCheck As String
Dim varOriginalSheet As Variant
'... some other non-relevant things
strRangeToCheck = "A5:HC231"
Set wbkOrig = Workbooks.Open(Filename:=FileStr)
Set wsOriginalWS = wbkOrig.Worksheets("Sheet1")
wsOriginalWS.Activate
With wsOriginalWS
Set varOriginalSheet = Range(strRangeToCheck)
End With
'... some other non-relevant things. At this point,
'... wbkOrig is still open, and I can see it with all of its data
'... while debugging.
itemp = getDimension(varOriginalSheet)
我已经确认Set varOriginalSheet = Range(strRangeToCheck)
之前的所有内容都有效。临时目录中的电子表格打开且不为空。由于某种原因,varOriginalSheet为空。
这是getDimensions:
Function getDimension(var As Variant) As Long
On Error GoTo Err
Dim i As Long
Dim tmp As Long
i = 0
Do While True
i = i + 1
tmp = UBound(var, i)
Loop
Err:
getDimension = i - 1
End Function