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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you add a reference during run time?

Status
Not open for further replies.

sonname

Programmer
May 18, 2001
115
0
0
US
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
 
You could always Late Bind the objects?

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

Crabback
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top