PDA

View Full Version : Issue with Paperport.ocx Reference



ASkolnick
02-01-2012, 02:41 PM
In previously existing Microsoft Word documents, we have a reference to
a file called Paperport.ocx that we didn't put in there and we don't want.

I have looked up a solution to eliminate bad references:
Sub Remove References
Dim ObjRef as Object
For Each objRef in ActiveDocument.VBProject.References
If (objRef.isbroken) then
activedocument.vbproject.references.remove objref
end if
next
set objref=nothing
End Sub

This solution had been working, but no longer is. The problem is that although it finds the bad reference, it does not know the name of the reference.

If I add a
debug.print. objref.name
the error I get is:
Method 'Name' of object 'Reference' failed.

If I don't get that, the error I get is:
Object Library not registered.

The references loaded are:
VBA
Word 12.0
OLE Automation
Office 12
Forms 2.0
Missing: Paperport Desktop
Normal

Any help is greatly appreciated

Paul_Hossler
02-03-2012, 09:46 AM
In word 2007 your code works, but of course it's hard to find a broken reference when you want one

Maybe try just indexing like in sub 2 below


Option Explicit

Sub Remove_References()
Dim ObjRef As Object
For Each ObjRef In ActiveDocument.VBProject.References
MsgBox ObjRef.Name ' <<<<<<<<<<<< works
If ObjRef.isbroken Then
ActiveDocument.VBProject.References.Remove ObjRef
End If
Next
Set ObjRef = Nothing
End Sub

Sub Remove_References_2()
Dim i As Long
For i = ActiveDocument.VBProject.References.Count To 1 Step -1
MsgBox ActiveDocument.VBProject.References(i).Name
If ActiveDocument.VBProject.References(i).isbroken Then
ActiveDocument.VBProject.References.Remove ActiveDocument.VBProject.References(i)
End If
Next
End Sub


Paul