Re: Late binding to .XLA library??

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jim Rech (jrrech_at_hotmail.com)
Date: 03/03/05


Date: Thu, 3 Mar 2005 16:16:27 -0500


>>However, the problem is that if VBA attempts to compile any code that
references the add-in BEFORE running the code that checks if the add-in
exists, the application will still halt with a compile error

Sorry, Lee, if I didn't spell out exactly what I was driving at...

- Do not set a reference in the VB project. Result-> No compile error.
- At run time, check to see if Add-in exists.
- If yes, run code similar to my first post to create the reference.
- If no, disable your functions, etc.

-- 
Jim Rech
Excel MVP
"Lee S" <Lee@xNoDirectReplyx.net> wrote in message 
news:DtGVd.35775$Tj7.26629@twister.socal.rr.com...
| Bob / Jim,
|
| Thanks for the ideas.
|
| In my particular situation, I don't mind if the add-in does not exist -- I
| will simply disable any features that reference the add-in.
|
| However, the problem is that if VBA attempts to compile any code that
| references the add-in BEFORE running the code that checks if the add-in
| exists, the application will still halt with a compile error.
|
| EXAMPLE 1:
| In this example, only the local class clsLocalClass makes any reference to
| the add-in.  However if the add-in does not exist the Workbook_Open event
| will never run because VBA will first attempt to compile BOTH the
| ThisWorkbook and clsLocalClass.  If the add-in is not loaded then the
| clsLocalClass compile will fail, and Workbook_Open will never run.
|
| In ThisWorkbook class:
| ============================================================
|
| Dim objLocal    As clsLocalClass
|
| Sub Workbook_Open()
| Dim sResult
|
|     On Error Resume Next
|     sResult = Application.AddIns("MyAddIn").Installed
|     If sResult Then
|         '' Add-in exists -- make use of it
|         Set objLocal = New clsLocalClass
|     Else
|         '' Add-in does not exist -- don't use features from Addin
|     End If
| End Sub
|
| ------------------------------------------------------------
| In clsLocalClass    (inside current project)
| ------------------------------------------------------------
| Dim objAddin    As AddIn.clsSomething
|
| Private Sub Class_Initialize()
|    Set objAddin = CreateSomething()
| End Sub
|
| ============================================================
|
| EXAMPLE 2:
| The code below WILL ACTUALLY WORK, but it seems risky.  I made two 
changes:
| changed the objLocal definition to Object instead on clsLocalClass, and I
| moved the New clsLocalClass line out of Workbook_Open.  In this particular
| scenario, VBA will not attempt to compile clsLocalClass, so the
| Workbook_Open event will run.
|
| It SEEMS RISKY trying to second-guess when/if VBA will decide to compile
| clsLocalClass.  My real-world scenario is obviously more complex, and if 
VBA
| were to attempt to compile clsLocalClass at any time for any reason, my
| application would halt.
|
| In ThisWorkbook:
| ============================================================
| Dim objLocal    As clsLocalClass
|
| Sub Workbook_Open()
| Dim sResult
|
|     On Error Resume Next
|     sResult = Application.AddIns("MyAddIn").Installed
|     If sResult Then
|         '' Add-in exists -- make use of it
|         IntializeApp
|     Else
|         '' Add-in does not exist -- don't use features from Addin
|     End If
| End Sub
|
| Private Sub IntializeApp()
|    Set objLocal = New clsLocalClass
| End Sub
|
| ------------------------------------------------------------
| In clsLocalClass    (inside current project)
| ------------------------------------------------------------
| Dim objAddin    As AddIn.clsSomething
|
| Private Sub Class_Initialize()
|    Set objAddin = CreateSomething()
| End Sub
|
| ============================================================
|
|
|
| "Jim Rech" <jrrech@hotmail.com> wrote in message
| news:%23ZwpOl%23HFHA.1096@tk2msftngp13.phx.gbl...
| > How about:
| >
| > ThisWorkbook.VBProject.References.AddFromFile "c:\book1.xla"
| >
| > -- 
| > Jim Rech
| > Excel MVP
| > "Lee S" <Lee@xNoDirectReplyx.net> wrote in message
| > news:47xVd.35543$Tj7.23591@twister.socal.rr.com...
| > | In my spreadsheet I have code that references functions and classes in
| an
| > | .XLA file.  When a user who does not have the .XLA file available 
opens
| > the
| > | spreadsheet they see a compile error when the Workbook Open event 
fires
| > | (even though the Open event itself does not call or even directly
| > reference
| > | any XLA resources).
| > |
| > | This actually makes perfect sense to me  ...  but that does not mean I
| > have
| > | to like it.
| > |
| > | Anyone know of a reliable way to prevent the compile error in this
| > | situation?
| > |
| > | Something comparable to late binding for functions in an XLA library
| would
| > | be nice.  Then I could check if the library exists before I decide
| whether
| > | to make the function calls.
| > |
| > | I have discovered that if arrange my code /just right/, I can avoid 
the
| > | error by convincing VBA not to compile the modules that reference the
| > | non-existent library -- however that is not reliable enough to release
| to
| > | the users.
| > |
| > | I am tempted to port my .XLA into a Visual Basic and compile it into 
an
| > | ActiveX DLL, but I figured I would check with the group to see if 
anyone
| > had
| > | a good idea on this.
| > |
| > | Thanks!
| > |        Lee
| > |
| > |
| >
| >
|
| 


Relevant Pages

  • Re: Late binding to .XLA library??
    ... I don't mind if the add-in does not exist -- I ... the application will still halt with a compile error. ... only the local class clsLocalClass makes any reference to ... Sub Workbook_Open ...
    (microsoft.public.excel.programming)
  • Re: Seeing Access 2003 table in Access 2007
    ... The reason you're not able to compile is likely because code is running. ... VBA code in your database will not be disabled from the get-go. ... I had a second missing reference which I ... Compile {ProjectName}, where is the name of your VBA ...
    (microsoft.public.access.gettingstarted)
  • Re: 7.0 wishlist?
    ... doing it at compile time runs into the problems shown. ... At least an NPE in seemingly-null-safe could would then be prima facie evidence of thread-unsafety in the null's source chain, and with a runtime check on the reference assignment the NPE will occur in one of blocks that participated in a race condition instead of somewhere random later on. ... void method ... For that, I have the thread hold the queue in a WeakReferenceand if the removemethod hits the timeout, it sleeps for a while holding no other references to the queue. ...
    (comp.lang.java.programmer)
  • Re: C#.net 2008 build problem
    ... To compile the big solution for the first time, ... references to the 'subversion' source control for the first time? ... To add a project reference for each project, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Library Database
    ... library database has a .Mde or .Accde extension. ... How can you call a function in a library database without ... then you must also compile the library first. ... But perhaps it matters because of the implicit reference ...
    (comp.databases.ms-access)