我使用以下系统将模型对象中间存储在 VBA Excel 中的 ThisWorkBook-Object 中。
In ThisWorkBook-对象
Private Type TView
Model As UIModel
'UserInterface As UIFrm
End Type
Private this As TView
Friend Property Get Model() As UIModel
Set Model = this.Model
End Property
Friend Property Set Model(ByVal value As UIModel)
Set this.Model = value
'Validate
End Property
从模块调用时
if ThisWorkBook.Model is nothing then
'Do Stuff
End If
ThisWorkBook 必须翻译成您的 Excel 语言(例如德语 DieseArbeitsMappe.Model)
这很有效,模型可以存储在以后调用,即使代码已经运行到最后并且通常所有对象都会被销毁。如果出现错误,即使 ThisWorkBook 对象中的模型也会被销毁并重新初始化。但现在问题是:
1. 这种方法有明显的缺点吗?
2. 有没有更安全的方式在 Excel-VBA 中中介存储对象?