strTemplate = “Test Letter.dot”
Set appWord = WScript.CreateObject(“Word.Application”)
Get the User Templates path from the Word Options dialog, using the DefaultFilePathprop-
erty with the argument:
strUserTemplatePath = appWord.Options.DefaultFilePath(2) _
& “\”
‘MsgBox “User templates path: “ & strUserTemplatePath
If strUserTemplatePath <> “\” Then
Set fso = _
WScript.CreateObject(“Scripting.FileSystemObject”)
strTemplatePath = strUserTemplatePath & strTemplate
MsgBox “Source template and path: “ & strTemplatePath
On Error Resume Next
Set fil = fso.GetFile(strTemplatePath)
If fil Is Nothing Then
strPrompt = “Can’t find “ & strTemplate & _
“ in “ & strTemplatePath & “ folder; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
Quit
Else
Set appWord = WScript.CreateObject(“Word.Application”)
appWord.Visible = true
Set docs = appWord.Documents
docs.Add(strTemplate)
End If
Else
strPrompt = _
“User template path not selected; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
End If
The New Worksheet from Template.vbs script listed next opens a new Excel worksheet based on
an Excel 2007 template located in the main User Templates folder:
Dim appExcel
Dim strTemplatePath
Dim strTemplate
Dim bks
Dim wkb
Dim wks
strTemplate = “Access Contacts.xltx”
Creating Standalone Scripts with Windows Script Host 17