VBA: conditional compilation with a keyword

Is it possible to use compiler conditional constants together with the keyword "implements", where the interface is in the add-in?

I have the following in the class module in my book, let me book1 it:

#Const Condition1 = 0 ''will be replaced with 1 when add-in is opened #if Condition1 then Implements myAddIn.iInterfaceFoo #End if 

I have an add-on myAddIn specified as a link (i.e. in Tools -> Links ...).

I successfully use the interface with other classes in the add-in, but now I want to call the interface directly in the book of book 1. While 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 a private add-in, I get an error

 Compile error: User-defined type not defined 

This is exactly what I'm trying to avoid - otherwise, if the add-in is missing (for example, on another computer), the table itself will work.

+6
source share
1 answer

I searched a lot and did not find a good solution to this problem.

So, I wrote the problematic function in another file, and if I need it, I activate it as follows:

On sp.mdb in the module:

 Public Function soap30object() As Object Set soap30object = New SoapClient30 End Function 

To 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 some fun!


Another solution

Replace the code in the module with 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 
+1
source

Source: https://habr.com/ru/post/1214493/


All Articles