PDA

View Full Version : Word Reference Library



IRish3538
12-17-2012, 01:52 PM
Hi all,

I've scoured the site looking for an answer but now I'm admitting defeat. I have an excel workbook with a ton of VBA in it that required a Word reference library. All was fine until my office started migrating from Windows XP to Windows 7.. which carry different versions of office. I'm trying to load the MSWord Reference Library on the fly (which I can do) and delete out the missing library if one exists (which isn't going so well)... Here's what I have that isn't working.. I get a run-time error that says "Error in Loading DLL" on the ".isbroken" line.

Sub word_ref()
Dim theRef As Variant, i As Long

'On Error Resume Next

'Remove any missing reference libraries
For i = ThisWorkbook.VBProject.References.count To 1 Step -1
Set theRef = ThisWorkbook.VBProject.References.Item(i)
If theRef.isbroken = True Then
ThisWorkbook.VBProject.References.Remove theRef

ThisWorkbook.VBProject.References.AddFromFile _
Application.Path & "\MSWORD.olb"
End If
Next i

End Sub

Dave
12-18-2012, 02:19 PM
I think it's a security thing about not programatically being able to add references. Use late binding and then you won't need the reference. HTH. Dave

Bob Phillips
12-18-2012, 04:38 PM
Or build your code with the lowest version of Word.

snb
12-25-2012, 09:59 AM
or do not try to remove anything:
Sub M_snb()
On Error Resume Next
ThisWorkbook.VBProject.References.AddFromFile Application.Path & "\" & Dir(Application.Path & "\*msword*")
End Sub