在附加到Excel 2003电子表格的某个VBA中,我需要使用一些需要一段时间才能实例化的对象 - 所以我只想做一次'set'事情......
显示代码比写出解释更容易!
' 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
答案 0 :(得分:6)
这应该有效:
If myObj IS Nothing Then
(注意“IS”)如果这不起作用,则必须由该类专门实现异步初始化,因为默认情况下COM init调用是同步的。因此,您需要检查文档,或者与开发人员讨论Big类的某些属性或者同步方法,以便您等待。