References Collection Events

Name

Parameters

Description

ItemAdded

Reference As VBIDE.Reference

Triggered when a Reference is added to the VBProject being watched.

ItemRemoved

Reference As VBIDE.Reference

Triggered when a Reference is removed from the VBProject being watched.

Putting the References collection to use, this example checks for broken references and alerts the user:

Function HasMissingRefs() As Boolean

Dim oRef As VBIDE.Reference

Function HasMissingRefs() As Boolean

Dim oRef As VBIDE.Reference

'Loop through all the references for the project For Each oRef In ThisWorkbook.VBProject.References

'Is it missing? If oRef.IsBroken Then

'Yes - show different messages for workbook and DLL references If oRef.Type = vbext_rk_Project Then

MsgBox

"Could not find the workbook " & oRef.FullPath & _

", which is required by this application."

Else

MsgBox

"This application requires the object library '" & _

oRef.Description & "', which has not been installed."

End If

'Return that there are some missing references

HasMissingRefs = True

End If

Next

0 0

Post a comment