Is it possible to use compiler conditional constants together with the "implements" keyword, where the interface is in an add-in?
I have the following in a class module in my workbook, let's call it book1:
#Const Condition1 = 0 ''will be replaced with 1 when add-in is opened
#if Condition1 then
Implements myAddIn.iInterfaceFoo
#End if
I have the add-in myAddIn listed as a reference (i.e. in Tools -> References...).
I'm successfully using the interface with other classes in the add-in, but now I want to call the interface directly in my workbook book1. As long as the add-in is open, when I compile book1 (i.e. Debug -> Compile VBAProject) it compiles successfully.
However, when I try to compile book1 with the add-in closed, I get the error
Compile error: User-defined type not defined
This is precisely what I'm trying to avoid - otherwise if the add-in is missing (for example on someone else's computer) the spreadsheet itself will still work.
I was looking a lot and didn't find a good solution to that problem.
So i wrote the problematic function in another file, and if i need it i activate it like this:
On sp.mdb in a module:
Public Function soap30object() As Object
Set soap30object = New SoapClient30
End Function
On the main file:
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
Have fun!
Another solution
Replace the code in Modul on Runtime...
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 Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With