PDA

View Full Version : Is it possible to programatically add a reference to a word template in VBA project?



dreamavatar
03-15-2016, 09:03 AM
I have a macro that is updated frequently and stored on a shared drive. I need to add a reference to this macro to several hundred existing word documents so it can be called on open. I have the code below which works if I manually add the reference to the the .docm file on the network drive. I am hoping there is a way to do this in mass instead of opening and manually adding the reference to each file.

Private Sub Document_Open()
On Error GoTo Escape
Call PROJECTNAME.MODULENAME.MACRONAME
Escape:
Exit Sub
End Sub



I understand that something like the line below is used for non user-created libraries but I have not been able to get it to work. I appreciate any assistance.

Application.VBE.ActiveVBProject.References.AddFromFile "J:\NETWORKDRIVE\DISTRIBUTION\SHAREDMACRO.DOTM"