Automatically removing and adding Reference for external tlb

Discussion created by e884479 on Oct 28, 2013
Latest reply on Oct 29, 2013 by RJKSolutions

 Hi all,


in this days I seached a lot for a solution adding an external reference to processbook using a vba code.


This was necessary, because one of our PDIs needs the reference to an external tlb and the installation path was diffrent under windows xp and windows 7.


So we have to remove an existing reference and to add a new refernce.


I think our solution could also be interessting for you. So I push my lessons learnd here in vcampus.


The sample shows how to add an reference to a afwrapper.tlb which is registered beside the processbook display.







Private Sub Display_Open()

' Automatically adding Reference needs Microsoft Visual Basic for Applications Extensebility    
    Set x = Application.VBE
    Dim Pfad As String
    Pfad = Mid(ThisDisplay.Path, 1, InStrRev(ThisDisplay.Path, "\")) & "AFWrapper.tlb"
    Dim str As String
    Dim a As Reference
    For Each a In x.ActiveVBProject.References
        If a.Name = "AFWrapper" Then
        x.ActiveVBProject.References.Remove a
        End If
    Next a
        x.ActiveVBProject.References.AddFromFile Pfad
End Sub









Hope you can use my solution






Chris Benitz