1
在某些附加到Excel 2003电子表格的VBA中,我需要使用一些需要一段时间才能实例化的对象 - 所以我只想执行一次'设置'的事情...如何知道对象是否已被引用?
这更容易显示代码比写一个解释!
' Declare the expensive object as global to this sheet
Dim myObj As SomeBigExpensiveObject
Private Sub CommandButtonDoIt_Click()
' Make sure we've got a ref to the object
If IsEmpty(myObj) Then ' this doesn't work!
Set myObj = New SomeBigExpensiveObject
End If
' ... etc
End Sub
如何检查myObj是否已设置?
我试过IsNull(myObj)和IsEmpty(myObj) - 无论myObj的状态如何都跳过'set'。我不能做
if myObj = Nil then
或
if myObj = Empty then
或
if myObj = Nothing then
任何想法?
SAL
您是否尝试过CreatObject? – THEn 2009-06-18 16:54:10
这个页面有关于VB/VBA中空,空和空白之间差异的很好的信息http://beta.blogs.msdn.com/ericlippert/archive/2003/09/30/53120.aspx – Lunatik 2009-06-19 05:31:14