• Set reference ‘on the fly’ (WinXP/Word2003 NL)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Set reference ‘on the fly’ (WinXP/Word2003 NL)

    Author
    Topic
    #421730

    I need to reference the dll C:Program FilesGeneraliBox.dll from a global template. No problem doing so at design time. But that means distribution of the dll to all users (1000+) of the global template. And the dll is only used by the 3 percent of the users with acces to a particular application. So I wonder if it is possible to set the reference “on the fly” when Word starts (module AutoExec, Sub Main in the global template), depending on the existence of that dll on the PC.

    Viewing 0 reply threads
    Author
    Replies
    • #959255

      If you set a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 library, you can manipulate references in code. Put the following macro in a module; you can run it to test if it works correctly, and if so, you can call it from the AutoExec macro.

      Sub TestRef()
      Const strLib = “C:Program FilesGeneraliBox.dll”
      If Not Dir(strLib) = “” Then
      ThisDocument.VBProject.References.AddFromFile strLib
      End If
      End Sub

      • #959256

        Thanks Hans, I’ll give that a try.

        • #959808

          (Edited by JanB on 14-Jul-05 10:26. edited some typo’s and added note)

          The code works fine, but that’s not enough to solve the problem. Removing the manually applied reference to the ibox.dll is causing a “Compile error in a hidden module” right at the start of Word. Delving into the code of a co-worker who is now on vacation, I learned that the cause is a line “Public gcDFC As New DfExSession” in the declarations section of a module (DFC = Documentum Foundation Class; Documentum is a document management system).
          So I’m trying to switch from this early binding to late binding by replacing the declaration line with “Public gcDFC As Object” and in Sub Main adding the line “gcDFC = CreateObject(“iBox”), but that fails with “Error 429, ActiveX-component cannot create object” (something like this, translated from Dutch). iBox is the name with which the dll presents itself in the Tools | Reference… dialog. As I’m not very familiar with this late binding, I’m stuck. What am I doing wrong?

          Note
          As I understand it, iBox is a sort of “communications layer” between VBA en DFC, also containing routines to add, edit & delete registry settings in the Documentum brache.

          • #959810

            If the early binding declaration is Public gcDFC As New DfExSession, the late binding equivalent is

            Public gcDFC As Object
            Set gcDFC = CreateObject(“iBox.DfExSession”)

            or perhaps

            Set gcDFC = CreateObject(“DfExSession”)

            You must change all declarations of objects associated with the iBox library to As Object.

            Also look out for symbolic constants defined in the iBox library, you must replace them with their values.

            • #959811

              Boy, are you fast!
              cheers

            • #961286

              I still cannot get this to work. Steps taken:
              – I made sure the dll is registered. I found it in the Registry under HKEY_CLASSES_ROOTCLSID{number}. In key ProgID, (Standard) has value iBox.DfExSession.
              – In a standard module, I put the declaration Public gcDFC As Object
              – In module AutoExec, Sub Main, I check if the iBox.dll is present in the correct path
              – If so, the line Set gcDFC = CreateObject(iBox.DfExSession) is executed
              – all code referring to gcDFC is in the Sub cmdOK_Click of a simple form with two textboxes to input username and password and an OK button
              – this form is only shown if the iBox.dll is present (only a few users, including my developer-PC)

              The line Set gcDFC = CreateObject(iBox.DfExSession) causes runtime error 438: “This property or method is not supported by this object”. Any ideas?

            • #961287

              Is the lack of quotes around iBox.DfExSession in Set gcDFC = CreateObject(iBox.DfExSession) just a typo?

            • #961289

              Oops, not a typo… blush stupidme
              Sometimes I appear to be completely blind for those little things. Thanks Hans!

    Viewing 0 reply threads
    Reply To: Set reference ‘on the fly’ (WinXP/Word2003 NL)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: