ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Broken References (https://www.excelbanter.com/excel-programming/292132-broken-references.html)

Gareth[_3_]

Broken References
 
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.




Tom Ogilvy

Broken References
 
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

--
Regards,
Tom Ogilvy


"Gareth" wrote in message
...
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.







All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com