1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
Sub addRefs()
On Error GoTo GestionErreur
Dim Ref As Reference
Const Cible = &H2B
Dim doesntExist As Boolean
Dim objShell As Object
Dim objFolder As Object, objFolderItem As Object
'La procédure boucle sur la collection de références et supprime celles qui sont
'spécifiées manquantes.
For Each Ref In ThisWorkbook.VBProject.References
If Ref.IsBroken = True Then
ThisWorkbook.VBProject.References.Remove Ref
doesntExist = True
End If
Next Ref
If doesntExist = True Then
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(Cible)
Set objFolderItem = objFolder.self
ThisWorkbook.VBProject.References.AddFromFile (objFolderItem.Path & "\System\ado\msadox.dll")
ThisWorkbook.VBProject.References.AddFromFile (objFolderItem.Path & "\System\ado\msador15.dll")
End If
Exit Sub
GestionErreur:
If Err.Number = 32813 Then
Resume Next
Else:
MsgBox ("Erreur numéro " & Err.Number & vbCrLf & Err.Description)
End If
End Sub |
Partager