Broken References

G

Gareth

I posted a few days ago and got the following cod to remove any 'MISSING'
References form my '97 file after it has been worked on in a newer version:

Sub removebrokenreferences()
Dim Counter As Integer
With ThisWorkbook.VBProject.References
For Counter = 1 To .Count
If .Item(Counter).IsBroken Then
.Remove .Item(Counter)
End If
Next
End With
End Sub

I can't seem to get it to work properly. In my Reference box I have 7
ticked, the last 2 are 'MISSING' and are obviously the ones I want to
remove. When I run the macro it gets rid of the first but not the second,
is it something to do with the .Count bit?

It counts 7 so checks 7 References, but after the 6th is checked and removed
because it is broken there isn't a 7th to check so instead looks at an
unticked reference which causes an error. The second 'MISSING' becomes the
6th in the box so is not checked.

Is my theory correct?

If so, is there a way around it?

Thanks in advance.
 
T

Tom Ogilvy

Sub removebrokenreferences()
Dim Counter As Integer
With ThisWorkbook.VBProject.References
For Counter = .Count To 1 Step -1
If .Item(Counter).IsBroken Then
.Remove .Item(Counter)
End If
Next
End With
End Sub
 

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