|
我自制了个公开类的外接程序,在VBA中调用没问题,但是在文档级程序中调用碰到问题:
1、接口声明实现均在一处,如,Sheet1中,
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim addIn As Office.COMAddIn = Globals.ThisWorkbook.Application.COMAddIns.Item("SWXLR")
Dim utilities As Object = TryCast(addIn.Object, Object)
end sub
utilities 结果实现,非空。
2、如果以上分开,如,在模块中声明(为了声明为公共变量方便调用),在 Thisworkbook启动中赋值,则无法实现,utilities 为 Nothing。
Module Module1
Public addIn As Office.COMAddIn
Public utilities As Object
End Module
Private Sub ThisWorkbook_Startup() Handles Me.Startup
addIn = Me.Application.COMAddIns.Item("SWXLR")
utilities = TryCast(addIn.Object, Object)
End Sub
想不明白怎么回事?请大家帮忙解决,谢谢!
|
|