是否可以使用编译器条件常量和“实现”关键字(接口在外接程序中)一起使用?
在我的工作簿中的类模块中有以下内容,让我们将其称为book1:
#Const Condition1 = 0 ''will be replaced with 1 when add-in is opened
#if Condition1 then
Implements myAddIn.iInterfaceFoo
#End if我将外接程序myAddIn作为引用列出(即在Tools ->引用中.)。
我正在成功地将接口与外接程序中的其他类一起使用,但现在我想在工作簿book1中直接调用该接口。只要外接程序是打开的,当我编译book1 (即调试->编译VBAProject)时,它就会成功编译。
但是,当我试图用加载项关闭编译book1时,我会得到错误。
Compile error: User-defined type not defined这正是我试图避免的--否则如果外接程序丢失(例如在其他人的计算机上),电子表格本身仍能工作。
发布于 2015-04-27 07:19:10
我看了很久,没有找到解决那个问题的好办法。
因此,我在另一个文件中编写了这个有问题的函数,如果我需要它,我会像这样激活它:
在模块中的sp.mdb上:
Public Function soap30object() As Object
Set soap30object = New SoapClient30
End Function在主文件上:
Public Sub soap30object()
Dim ob As Object
Dim appAccess As New Access.Application
appAccess.OpenCurrentDatabase ("c:\sp\sp.mdb")
Set ob = appAccess.Run("soap30object")
End Sub玩得开心!
另一种解决办法
替换运行时模块中的代码..。
Public Sub replacemodel(mdlname As String, fnd As String, cngto As String)
Dim toi As Long, oldlin As String, i As Long, firstchr As String, linnewnum As Long, last_ As Boolean
Dim frm As Form,mdl As Module
DoCmd.OpenForm mdlname, acDesign
Set mdl = Forms(mdlname).Module
toi = mdl.CountOfLines
With mdl
For i = 1 To toi
linnewnum = i
oldlin = .lines(i, 1)
If InStr(oldlin, fnd) <> 0 Then
oldlin = Replace(oldlin, fnd, cngto)
.ReplaceLine i, oldlin
goto nexx
End If
Next i
End With
nexx:
DoCmd.Close acForm, mdlname, acSaveYes
Set mdl = Nothing
'All variables reset when you edit modul on
msgbox "Program will restart now..."
DoCmd.Quit acQuitSaveAll
end Subhttps://stackoverflow.com/questions/28815255
复制相似问题