Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep Excel from binding to the Microsoft Word 15.0 Object Library?

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?

like image 490
Webaphile Avatar asked Oct 20 '22 15:10

Webaphile


2 Answers

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.

like image 114
Jean-François Corbett Avatar answered Oct 22 '22 23:10

Jean-François Corbett


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
like image 33
mrbungle Avatar answered Oct 22 '22 23:10

mrbungle