Conflicting VBE references

gifariz

Board Regular
Joined
May 2, 2021
Messages
112
Office Version
  1. 365
Platform
  1. Windows
I have references that use API library to interact with other software.
I have multiple different versions of this software installed in my computer, lets say ProgramA 2021 and ProgramA 2022.
The paths of reference are:
"C:\Program Files\CompanyX\ProgramA 2021\ProgramAv1.tlb"
"C:\Program Files\CompanyX\ProgramA 2022\ProgramAv1.tlb"
So the folder are different, but reference file name and description are same.
The problem is I cannot change the reference to older version (either manually by VBE interface tools->reference->browse, or by coding using Ms VBA Extensibility 5.3 library), hence I connect to the older software by API.
Is there possible solution from excel VBA side? Or this is purely issue from that software (e.g. the software have only one reference GUID that overwrites all older versions during installation)?
TIA
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What VBA Extensibility 5.3 library code are you using to change the references? Do you try removing both before adding them?
 
Upvote 0
Edit in post: ....., hence I cannot connect to the older software by API.

What VBA Extensibility 5.3 library code are you using to change the references? Do you try removing both before adding them?
Yes I do that. I believe my code is okay, I debugged each process. It looks like this (simplified code):

VBA Code:
Sub RemoveAddVBEReference()

    Dim oRef As VBIDE.Reference
    Dim oRefs As VBIDE.References
   
    Set oRefs = Application.VBE.ActiveVBProject.References
   
    For Each oRef In oRefs
        If oRef.FullPath = "C:\Program Files\CompanyX\ProgramA 2022\ProgramAv1.tlb" Then
            oRefs.Remove oRef
        End If
    Next oRef
    oRefs.AddFromFile "C:\Program Files\CompanyX\ProgramA 2021\ProgramAv1.tlb"

End Sub
 
Upvote 0
Ok - I assume there is more to it than this? Because this only removes the 2022 reference, and only adds the 2021 reference. It doesn't remove both, nor does it add both.
What is it in these type libraries that you're trying to access? Declared API functions?
 
Upvote 0
Ok - I assume there is more to it than this? Because this only removes the 2022 reference, and only adds the 2021 reference. It doesn't remove both, nor does it add both.
Ah yes right, I missed that when simplifying the code. The reference description is used as criteria to remove the reference, so all versions will be removed before selected version is added. And btw, there is always only one reference of program exist, which is always the latest version when any reference version is added.
VBA Code:
Sub RemoveAddVBEReference()

    Dim oRef As VBIDE.Reference
    Dim oRefs As VBIDE.References
    Dim TempStr() As String
   
    Set oRefs = Application.VBE.ActiveVBProject.References
   
    For Each oRef In oRefs
        TempStr = Split(oRef.Description, " ")
        If TempStr(0) = "ProgramA" Then oRefs.Remove oRef
    Next oRef
    oRefs.AddFromFile "C:\Program Files\CompanyX\ProgramA 2021\ProgramAv1.tlb"    'When this line is commented, I checked there is no programA reference (removed).


End Sub

What is it in these type libraries that you're trying to access? Declared API functions?
I cannot even connect to the older program, e.g. by GetObject.
VBA Code:
Sub ConnectAPI()
    Dim myObject As ProgramA.cAPI
    Set myObject = GetObject(, "CompanyA.API.ProgramA") 'Success to get object when latest version of program is being used,
                                                        'unable to get object when older version of program is being used.
End Sub
 
Upvote 0
Without knowing anything about the type libraries, their contents, etc., it's tricky to advise, but I suppose the default point would be if the type libraries contain the same references, API declarations, objects, then you're going to need a way of telling VBA which one you're trying to reference. I don't understand what the older version/new version of the "program" means, but I think that you need to go through a process of debugging - try and limit one workbook to one type library - see if they work independently of each other.
 
Upvote 0
Without knowing anything about the type libraries, their contents, etc., it's tricky to advise, but I suppose the default point would be if the type libraries contain the same references, API declarations, objects, then you're going to need a way of telling VBA which one you're trying to reference. I don't understand what the older version/new version of the "program" means, but I think that you need to go through a process of debugging - try and limit one workbook to one type library - see if they work independently of each other.
The problem is actually before going to contents inside the reference, it is the not being able to merely connecting to older program by GetObject function. The contents of different versions of the program are exactly same. "Try limit one workbook to one type library", that is actually the problem, there is only one type library and it is always the latest version of program that I'm unable to change, so I cannot connect when older version of program is being used. I understand that it's hard to solve this without knowing the library and using the program, so thank you for trying to help, I appreciate it.
 
Upvote 0

Forum statistics

Threads
1,215,197
Messages
6,123,581
Members
449,108
Latest member
rache47

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top