We have a very complex Excel 2010 spreadsheet template. Each new copy of the template needs to pass through several people during its lifetime.
Unfortunately, one of the first people to utilize the template has Office 365 installed. After he has touched it, the spreadsheet appears to bind to the Microsoft Word 15.0 Object library, which is not available on the Excel 2010 PCs. While an individual broken file can be fixed by unchecking the missing Word object library in the VBA Code Tools > References, I need to find a way to prevent this from happening in the first place.
I have reviewed the code in detail and I cannot find any reference to the MS Word Object library, so what is causing Excel to bind to it in the first place? Is there anything I can do to prevent it?
Untested, but putting something like this in your Workbook_BeforeSave
event would probably work:
With ThisWorkbook.VBProject.References
For i = .Count To 1 Step -1
If InStr(.Item(i).Name, "Word") <> 0 Then .Remove .Item(i)
Next
End With
Disclaimer: I don't have Office 365 and don't know why it would automatically add a reference to Word 15.0; anyhow, the above assumes that it does.
To Remove, place inside module: I know this dosen't prevent it from happening in the first place but this might help to at least remove it before the next person.
Private Sub RemoveRef()
Dim Reference As Object
For Each Reference In ThisWorkbook.VBProject.References
If Reference.Description = "Microsoft Word 15.0 Object library" Then
ThisWorkbook.VBProject.References.Remove Reference
End If
Next
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With