I have a word module that uses some objects, I keep losing the reference from the Tools/References. Is there a way that I can set this when I load the word project so that it sets those references before the object is called? Thanks
HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
I just did this in excel to check if the MSCOMDLG was referenced, if its not then the it is added to the references. It works great. Heres my code, you'll just need to tweak a bit for Word.
*** This sub calls the function TestComDlg32Reference to *** check if the reference already exists.
*** if it doesn't a reference is made
Sub LoadComDlg32Reference()
'Call TestComDlg32Reference in IF
If TestComDlg32Reference = False Then _
ThisWorkbook.VBProject.References.AddFromFile "C:\Windows\System32\comdlg32.ocx"
Exit Sub
End Sub
Function TestComDlg32Reference() As Boolean
Dim obj
For Each obj In ThisWorkbook.VBProject.References
If UCase(obj.Name) = "MSCOMDLG" Then
TestComDlg32Reference = True
Exit For
Else
TestComDlg32Reference = False
End If
Next obj
Exit Function
End Function
... You just need to call the sub from your somewhere within your code - another sub or from startup
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.