Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Invalid References

Status
Not open for further replies.

mveera

Programmer
Nov 6, 2002
81
US
Hi,

I have a workbook which will be used in both office 2000 and XP. the workbook developed in 2000 and has a reference to Word 9.0 object library(MSWORD9.OLB). I add this reference automatically when the WB opens.
But in office XP the Word object library version as changed and it shows an invalid reference error in the References dialog box.

How can i search and remove invalid refrences so that i can add the new reference?

Thanks
Veera
 
You may put the next code to the Auto_Open event:

Code:
Sub Ref_or_Not()
Dim ItIs As Boolean, i As Long: ItIs = False
 If Application.OperatingSystem = "Windows (32-bit) NT 5.01" Then
   For i = 1 To ThisWorkbook.VBProject.References.Count
    If ThisWorkbook.VBProject.References(i).Name = "Word" Then
    ItIs = True
   End If
 Next i
 If ItIs = False Then Ref_Add
 Else
   For i = 1 To ThisWorkbook.VBProject.References.Count
    If ThisWorkbook.VBProject.References(i).Name = "Word" Then
      ThisWorkbook.VBProject.References.Remove _
                     ThisWorkbook.VBProject.References("Word")
  'Here you may put an appropriate reference 
    End If
   Next i
 End If
End Sub

Sub Ref_Add()
Dim RefAdd As String
 RefAdd = "C:\Program Files\Microsoft Office\Office\MSWORD9.OLB"
 ThisWorkbook.VBProject.References.AddFromFile RefAdd
End Sub

You can play with adding or removing a reference with the code above but I don't know how this will work when the reference is not valid . I tested it only in XP and I did not have problems in addin and removing it. Anyhow the reference you say that missis from XP it looks to be in my system....


I hope this helps...
FaneDuru'
 
Hi mveera,

There is no guarantee that the versions of Excel and Word are the same but would it help to check Application.Version and then try to add the appropriate reference (Word 9.0 or Word 10.0) rather than always adding Word 9?

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top