ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to test if a DLL (library) exists (https://www.excelbanter.com/excel-programming/336615-how-test-if-dll-library-exists.html)

ExcelMonkey

How to test if a DLL (library) exists
 
How do I test in VBA to see if a particual DLL exists in my references? I
want to test to see if the RegExp library exists and if so I want to check it
off. If it does not exist I want o generate an error message prompting the
user that the file is not available in the libraries.

On a side note, I am assuming that the library should be available. Why
would it not be? Is there any reason that xl97 upward would not have this?
And if it is not available, what are the users options (assuming this may be
driven by version of Excel). For example, say the user had it but
accidentally deleted it. What would they need to do to restore it?

Thanks

Rob Hargreaves[_2_]

How to test if a DLL (library) exists
 
Hi xlmonkey

If you open the vb editor window and go to tools and then references you
will see the referenced dlls in the dialog that comes up.

Depending on what you are doing you will have to know which will be ticked
in the list.

You cannot get to this option in debug mode.

you can check for any file at a known path through vba

Sub FileExists()
Dim fso
Dim file As String
file = "C:\Test.xls" ' change to match the file w/Path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(file) Then
MsgBox file & " was not located.", vbInformation, "File Not Found"
Else
MsgBox file & " has been located.", vbInformation, "File Found"
End If
End Sub

You could maybe use a shell command through vba to register or unregister
dlls as librarys through vba.

I have done it with regsrv for windows files before but only through
start... run... dialogue in the windows start bar.

Search google forr info on this.

Hope that helps

Rob

"ExcelMonkey" wrote in message
...
How do I test in VBA to see if a particual DLL exists in my references? I
want to test to see if the RegExp library exists and if so I want to check
it
off. If it does not exist I want o generate an error message prompting
the
user that the file is not available in the libraries.

On a side note, I am assuming that the library should be available. Why
would it not be? Is there any reason that xl97 upward would not have
this?
And if it is not available, what are the users options (assuming this may
be
driven by version of Excel). For example, say the user had it but
accidentally deleted it. What would they need to do to restore it?

Thanks





Bob Phillips[_6_]

How to test if a DLL (library) exists
 
Give this a whirl

Dim ref As Object
Dim fRef As Boolean

fRef = False
For Each ref In ThisWorkbook.VBProject.References
If ref.Name = "VBScript_RegExp_55" Then
Debug.Print ref.Name
ThisWorkbook.VBProject.References.Remove ref
fRef = True
End If
Next
If Not fRef Then MsgBox "No ref set"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"ExcelMonkey" wrote in message
...
How do I test in VBA to see if a particual DLL exists in my references? I
want to test to see if the RegExp library exists and if so I want to check

it
off. If it does not exist I want o generate an error message prompting

the
user that the file is not available in the libraries.

On a side note, I am assuming that the library should be available. Why
would it not be? Is there any reason that xl97 upward would not have

this?
And if it is not available, what are the users options (assuming this may

be
driven by version of Excel). For example, say the user had it but
accidentally deleted it. What would they need to do to restore it?

Thanks





All times are GMT +1. The time now is 04:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com