I am trying to write a VB Script that opens word documents one by one in a specified path, links those documents to a .dot template I have created and then executes two macros ("ViewPrintLayout" and "ProcedureFormatBulletPoints") that is located within that template.
I have managed to get the script to open the documents and try to execute the macro. However it fails because I have not been able to successfully link it to the template. A copy of my code is below;
Dim objWord, objFSO, objFile, objFolder
strPath = InputBox("Enter Path Name")
If strPath = "" Then WScript.Quit
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder(strPath)
Set objWord = WScript.CreateObject("Word.Application")
objWord.Visible = True
For Each objFile In ObjFolder.Files
If LCase(Right(objFile.Path, 4)) = ".doc" Then
objWord.AddIns.Add FileName:="\My Documents\MEGA\PDF Templates\MyTemplate.dot"
Can anyone help explain why this does not work? I get a runtime error. Kind Regards.
Maybe you can find some useful code here:
the code in this MS page is mainly to detach/reset the .dot template of a doc file to the standard/default .dot/template, but maybe you can use a similar code to attach/link a new .dot template to an existing doc file.
As of today I'm trying to reuse this old code to reset the .dot file in some hundreds of old .doc files... (the .dot file referenced in the .doc files doesn't exist any more, and this is causing a lot of delay each time you open these .doc file)