Check for missing references

E

e.mel

I have a form that calls a 'open file' dialogue box, and requires
Microsoft Office 10.0 Object Library.

I would like to check in the code if the reference is valid, and if not
present an plain InputBox(...) and maybe a little blurb on how to
activate the reference.

the problem is the the "variable not defined" error is triggered before
any code is run so I cant use OnError to catch it.

Ideally the best solution would be to use the code to activate the
reference, but I dont think that is possible.
 
K

Klatuu

You can determine if it exists and whether it is broken. You can even tell
what the path to it is. The only problem is, the FullPath property is read
only.
Here is a function that will look for a specific reference and check to see
if it is broken.

Dim refs As References
Dim ref As Reference
Dim app As Application
Dim strRef As String

Set app = Application
Set refs = app.References

GetRef = "Reference Not Found"
For Each ref In refs
If ref.Name = "Office" Then
If ref.IsBroken Then
GetRef = "Broken Reference"
Else
GetRef = "Reference Is Good"
End If
Exit For
End If
Next ref

Set ref = Nothing
Set refs = Nothing
Set app = Nothing

End Function
 
E

e.mel

Thanks, that works great, but I found a better solution.
Turns out that all it was getting from the reference was a constant
(msoFileDialogFilePicker) which I just replaced with the literal value
(3) and now it works fine even without the reference checked off.
Im guessing Application.FileDialog is already in the Microsoft Access
10.0 Object Library

well good enough
 
K

Klatuu

That will work as long as nobody changes the priority in the references
dialog. If that is changed, the index will no longer be 3. That is why I
suggested using the name.
 
D

Dirk Goldgar

Klatuu said:
That will work as long as nobody changes the priority in the
references dialog. If that is changed, the index will no longer be
3. That is why I suggested using the name.

I'm not following you, Klatuu. e.mel can use late binding to access the
FileDialog without needing the reference, and the enumeration value 3
for msoFileDialogFilePicker will be perfectly valid, and independent of
the references.
 
K

Klatuu

I understand the late binding part. That is the way I usually do it. The
other part I am having a problem with. For example, in my current application:

?application.References(3).Name
Excel

Some enlightenment would be appreciated.
 
D

Dirk Goldgar

Klatuu said:
I understand the late binding part. That is the way I usually do it.
The other part I am having a problem with. For example, in my current
application:

?application.References(3).Name
Excel

Some enlightenment would be appreciated.

I think we're talking sideways. I think e.mel was talking about the
fact that the defined constant msoFileDialogFilePicker, which is defined
in the MS Office library, has a value of 3, so one can write code like
this:

Dim vFile As Variant

With Application.FileDialog(3)
.AllowMultiSelect = True
.Show
For Each vFile In .SelectedItems
Debug.Print vFile
Next vFile
End With

.... without ever setting a reference to the MS Office library.
 
K

Klatuu

I understand; however, I was going by the original post:

I have a form that calls a 'open file' dialogue box, and requires
Microsoft Office 10.0 Object Library.
 
Top