Access.2007.VBA.Bibl..

(John Hannent) #1
Else
strPrompt = _
“Workgroup template path not selected; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
End If

One or the other of these files (with the appropriate template name replacing “Test.dot”) would be
useful as part of an Office application that includes one or more Word templates; all the user needs
to do to install the template(s) in the right location is to run the script.

If you need to copy a set of templates to the User Templates or Workgroup Templates folder, you
don’t need to hard-code the template names, so long as the templates you want to copy are the
only templates in the current folder. The CopyAllTemplates.vbs script listed next copies all the
Word 2007 (*.dotx) templates in the current folder to the User Templates folder:

Dim strTemplate
Dim strUserTemplatePath
Dim appWord
Dim fso
Dim strScriptPath
Dim strScriptName
Dim strScriptNameAndPath
Dim fil
Dim filTemplate
Dim strPrompt
Dim strTemplatePath

strScriptName = WScript.ScriptName
strScriptNameAndPath = WScript.ScriptFullName

Get the path of the current script:

strScriptPath = Mid(strScriptNameAndPath, 1, _
Len(strScriptNameAndPath) - Len(strScriptName))

Get the User Templates path from the Word Options dialog, using the DefaultFilePathprop-
erty with the 2 argument:

Set appWord = WScript.CreateObject(“Word.Application”)
strUserTemplatePath = appWord.Options.DefaultFilePath(2) _
& “\”
‘MsgBox “User templates path: “ & strUserTemplatePath
If strUserTemplatePath <> “\” Then
Set fso = _
WScript.CreateObject(“Scripting.FileSystemObject”)
Set fld = fso.GetFolder(strScriptPath)

Part III Adding More Functionality to Office

Free download pdf