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

How do I add a reference using vba in Word?

Status
Not open for further replies.

mimitch

Programmer
Jun 30, 2011
5
US
I saw that there was code listed here for adding references in Access. Has anyone done the same in Word?

Thanks.
 
Ok. I tried using the code in WORD. This part "Dim loRef As Access.Reference" does not work. There is not equivalent "WORD.Reference" A "User-defined type not defined" error occurs.

Suggestions???
 


Please post all your code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Sub Macro36()
'
' Macro36 Macro
' Macro recorded 06/01/2011 by Michael Mitchell
'
Dim loRef As Word.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String

On Error Resume Next

Debug.Print "----------------- Add References -----------------------"

With Word.References
.AddFromFile "C:\Program Files\RTIMEV4\BIN\RTIME.tbl"
End With
End Sub
 


Code:
    Dim ref As Reference
    
'add this reference for file
    Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\system32\iasrad.dll"
    
'check to see if reference was added
    For Each ref In Application.VBE.ActiveVBProject.References
    
        Debug.Print ref.Name & " " & ref.FullPath
        
    Next ref

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Well it did not like the Dim statement; however, the "Application.VBE.ActiveVBProject.References.AddFromFile" piece worked like a champ.

Much thanks.
 

Well it did not like the Dim statement
Set a reference to Visual Basic for Applications Extinsibility.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top