[算表] 物件阵列在"With"之后变成Empty

楼主: foolkids (翼をください)   2016-08-22 21:20:03
软件:Office Excel
版本:2010
标题有点难懂,请直接看档案:https://goo.gl/No20Py (dropbox连结)
宏内容如下:
Sub AryTest()
Dim ShtAry As Variant
ShtAry = Array(工作表1, 工作表3) '将工作表设成阵列
MsgBox TypeName(ShtAry(0)) '先传回阵列第一个值的资料型态 = Worksheet
With ShtAry(0) '经过 with 之后
MsgBox TypeName(ShtAry(0)) '传回阵列第一个值的资料型态 = Empty
.Cells(1, 1) = "Yes" '但是仍可以继续使用With的物件
End With
With ShtAry(0) '第二次 with
MsgBox TypeName(ShtAry(0))
.Cells(1, 1) = "Yes*2" '已无法使用该物件
End With
End Sub
上述状况透过区域变量的监看视窗,确实发现一旦使用了 with 之后,
该阵列内的资料型态就会从 Worksheet 变成 Empty...
请问各位高手,这是什么原因呢?谢谢!!

Links booklink

Contact Us: admin [ a t ] ucptt.com