If you set a reference to the ide, you can control it programatically. In vba, the reference is "Microsoft Visual Basic for Applications Extensibility 5.3". I don't remember what it is for VB. I wrote the following subs to load references by filename or guid.
Public Function SetReferenceByFile(FilePath As String, Optional DisplayErrors As Boolean) As VBIDE.Reference
'returns True if successful in setting a reference in the current dvb,
'given the FilePath of a tlb, olb, dll. The DisplayErrors option determines
'whether or not an error message will be displayed upon erroring.
On Error GoTo ErrorHandler
Dim objVB As Object 'VBE
Dim objRef As VBIDE.Reference
Dim objRefs As VBIDE.References
Dim strPath As String
Set objVB = AcadApplication.VBE
Set objRef = objVB.ActiveVBProject.References.AddFromFile(FilePath)
SetReferenceByFile = True
GoTo Finish:
ErrorHandler:
If Err.Number = 32813 Then
'reference was already set, just return the reference
Set objRefs = objVB.ActiveVBProject.References
For Each objRef In objRefs
If objRef.FullPath = FilePath Then
Set SetReferenceByFile = objRef
End If
Next objRef
Else
If DisplayErrors = True Then
MsgBox Err.Number & ", " & Err.Description, vbExclamation, "SetReferenceByFile."
Else
End If
Set SetReferenceByFile = Nothing
End If
Finish:
Set objVB = Nothing
Set objRef = Nothing
End Function
Public Function SetReferenceByGUID(strGUID As String, maj As Long, min As Long) As VBIDE.Reference
'Returns a Reference object if successful in setting a reference in the current dvb,
'given the GUID of a tlb, olb, dll. Using a GUID avoids having to test
'for a valid filepath.
On Error GoTo ErrorHandler
Dim objVB As VBE
Dim objRef As VBIDE.Reference
Dim objRefs As VBIDE.References
Dim strPath As String
Set objVB = Application.VBE
Set objRef = objVB.ActiveVBProject.References.AddFromGuid(strGUID, maj, min)
Set SetReferenceByGUID = objRef
GoTo Finish:
ErrorHandler:
If Err.Number = 32813 Then
'reference was already set, just return the reference
Set objRefs = objVB.ActiveVBProject.References
For Each objRef In objRefs
If objRef.GUID = strGUID Then
Set SetReferenceByGUID = objRef
End If
Next objRef
Else
Set SetReferenceByGUID = Nothing
End If
Finish:
Set objVB = Nothing
Set objRef = Nothing
End Function
Ed
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to
post your code.