Hi guys,
I am more of an excel VBA guy and I am having an issue with below macro to attach templates to Word Documents in the same folder as an open file. The issue has arisen when testing the new office and finding out .FileSearch has been removed.
The code seems to work in excel (when I change .docx to .xls) but in word I'm having issues with the sPath Dim.
Any assistance would be greatly appreciated.
Joe
Code
Sub AttachTemplate()
Dim i As Integer
Dim oTemplate As Template
Set oTemplate = ActiveDocument.AttachedTemplate
Dim sPath
Set sPath = ActiveDocument.Path
sDir = Dir$(sPath & "*.docx", vbNormal)
Do Until LenB(sDir) = 0
Set oWB = Workbooks.Open(sPath & sDir)
For i = 1 To Documents.Count
If Not Documents(i).FullName = ActiveDocument.FullName Then
Documents(i).AttachedTemplate = oTemplate
Documents(i).UpdateStyles
End If
Next i
oWB.Close
sDir = Dir$
Loop
End Sub
Display More