Sub SwitchTemplates()
Dim strMyTemplate As String
strMyTemplate = ActiveDocument.AttachedTemplate.Name
ActiveDocument.AttachedTemplate = Application.NormalTemplate
FileCopy "WorkTemplatesFolder\strMyTemplate", Application.NormalTemplate.Path
ActiveDocument.AttachedTemplate = strMyTemplate
End Sub
Application.AddIns(Environ("AppData") & "\Microsoft\Word\STARTUP\MyTestAddIn1.dotm").Delete
source = "c:\test\MyTestAddIn2.dotm" 'newer version
destination = Environ("AppData") & "\Microsoft\Word\STARTUP\MyTestAddIn2.dotm"
Call FSO.copyfile(source, destination, True)
Application.AddIns.Add (Environ("AppData") & "\Microsoft\Word\STARTUP\MyTestAddIn2.dotm")
FSO.deletefile (Environ("AppData") & "\Microsoft\Word\STARTUP\MyTestAddIn1.dotm")
This successfully unloads version1, copies version2, and loads version2. But it gives me a permissions error when it tries to delete version1 from the STARTP folder. Word still thinks that file is open or loaded or something. I need to delete the old version otherwise next time I launch Word I get both version1 and version2 tabs, which I don't want. I tried copying the new version over the old version keeping the same name but run into the same permissions error. msgbox to ask "Update now, it will need to close Word?", quit if they say "no"
Write batch file
batchname = "e:\temp\wordupdate.cmd"
x = Shell("""" & batchname & """", vbNormalFocus)
Application.Quit (True)
@echo off
color 4F
mode 60,20
Echo Your Word addin needs to be updated.
Echo Please press a key to start this, will continue in 10 sec
Echo.
Timeout 10
echo Do your update xcopy
color 2F
cls
echo Update complete. Press any key to start Word
timeout 10
START winword