[算表] 物件陣列在"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