Remove a Reference Library from code

S

scott

I'm using the code below to add a reference library. Is there a vba way to
remove a reference if it exists?


CODE *********

Function ReferenceFromFile(strFileName As String) As Boolean
Dim ref As Reference
On Error GoTo Error_ReferenceFromFile

Set ref = References.AddFromFile(strFileName)
ReferenceFromFile = True

Exit_ReferenceFromFile:
Exit Function

Error_ReferenceFromFile:
Select Case Err.Number
Case 32813 ' Name conflicts with existing module, project or object
library. The reference is already set!
ReferenceFromFile = True
Case Else
'MsgBox ("Error # " & str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
ReferenceFromFile = False
Resume Exit_ReferenceFromFile
End Select

End Function
 
S

scott

I found the below code that removes a reference, but how can i modify it to
check for theexistance of the library before removing it, so there's no
error?

CODE ******

Function RemoveReference()
Dim ref As Reference
Set ref = References!ADODB
References.Remove ref
End Function
 
S

scott

i got it. thanks.


scott said:
I found the below code that removes a reference, but how can i modify it to
check for theexistance of the library before removing it, so there's no
error?

CODE ******

Function RemoveReference()
Dim ref As Reference
Set ref = References!ADODB
References.Remove ref
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top