Sie sind auf Seite 1von 2

*** In a Standard Module *** Option Explicit Sub References_RemoveMissing() 'Macro purpose: To remove missing references from the

VBE Dim theRef As Variant, i As Long On Error Resume Next For i = ThisWorkbook.VBProject.References.Count To 1 Step -1 Set theRef = ThisWorkbook.VBProject.References.Item(i) If theRef.isbroken = True Then ThisWorkbook.VBProject.References.Remove theRef End If Next i If Err <> 0 Then MsgBox "A missing reference has been encountered!" _ & "You will need to remove the reference manually.", _ vbCritical, "Unable To Remove Missing Reference" End If On Error Goto 0 End Sub *** In the ThisWorkbook Module *** Private Sub Workbook_Open() Call References_RemoveMissing End Sub

How to use:

1. 2. 3. 4. 5. 6. 7. 8.

Copy the References_RemoveMissing subroutine. In Excel press Alt + F11 to enter the VBE. Press Ctrl + R to show the Project Explorer. Right-click desired file on left (in bold). Choose Insert -> Module. Paste the code into the right pane. Copy the Workbook_Open event from the window above. Locate the project's "ThisWorkbook" module in the Project Explorer and double click it. 9. Paste the code into the right pane. 10. Press Alt + Q to close the VBE. 11. Save workbook before any other changes.

Test the code:

1. Download the attached file and open up the VBE (Alt + F11) 2. In the highest version of Office that you have access to, set a

reference to the desired library. (Tools References) 3. Save the file. 4. Send it to another PC with a lower version of Office. 5. The file will list all references, and should strip all invalid references upon opening. 6. 7. ALTERNATELY (if you have the lower version of office) 8. Download the attached file and open up the VBE (Alt + F11) 9. Set a reference to the desired library. (Tools References) 10. Save the file. 11. Send it to a computer with a higher version of office, and get the user to open it. (All references will automatically be upgraded.) 12. Have the user save the file and return it to you. 13. The file will list all references, and should strip all invalid references upon opening. 14. (If you need to reset them, see http://www.vbaexpress.com/kb/getapprovalarticle.php?kb_id=267)

Das könnte Ihnen auch gefallen