Programmatically remove broken reference

R

RB Smissaert

How do I in Word remove a broken (ticked in Tools, References, but showing
as Missing) reference?

I tried code like this:

Sub RemoveBrokenReferences()

Dim VBProj As Object
Dim oRef As Object

On Error Resume Next

Set VBProj = ThisDocument.VBProject

For Each oRef In VBProj.References
If oRef.IsBroken Then
VBProj.References.REMOVE oRef
End If
Next oRef

End Sub

and I also tried removing by name and by index number, but it all fails.


RBS
 
T

The Code Cage Team

Try this for checking for references and removing broken ones!

Sub get_or_repair_refs()
Dim RefC
For RefC = 1 To Application.VBE.ActiveVBProject.References.Count
RefName
Application.VBE.ActiveVBProject.References(RefC).Name
RefDesc
Application.VBE.ActiveVBProject.References(RefC).Description
If Application.VBE.ActiveVBProject.References(RefC).IsBroken
True Then
RefBroken = True
End If
Next RefC

End Su

--
The Code Cage Tea

Regards,
The Code Cage Team
www.thecodecage.co
 
R

RB Smissaert

Thanks for the reply, but I don't see that code removing a reference.
Did you try it with a broken reference?

RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top