Copy all Word 2007 (*.dotx) templates from the current folder to User Templates folder, with a
message box for each one (comment out the MsgBoxline to suppress these messages):
lngCount = 0
For Each fil In fld.Files
If Right(fil.Name, 4) = “dotx” Then
strTemplate = fil.Name
fil.Copy strUserTemplatePath, True
MsgBox strTemplate & “ copied to “ _
& strUserTemplatePath
lngCount = lngCount + 1
End If
Next
Else
strPrompt = _
“User template path not selected; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
End If
The sample database for this chapter is Northwind.accdb. This is a version of the
sample Northwind database, with its tables renamed according to the Leszynski
Naming Convention.
Office Scripts ..........................................................................................................
PrintReport.vbs demonstrates another use of scripts; it prints a report from Northwind.accdb,
without the need to open the database. This could be handy if you need to print out labels on a
regular basis. The code for this script is listed as follows:
Dim appAccess
Dim strDBName
Set appAccess = _
WScript.CreateObject(“Access.Application”)
Set fso = _
WScript.CreateObject(“Scripting.FileSystemObject”)
Modify the hard-coded file path as needed for your system:
strDBName = “D:\Documents\Northwind.accdb”
On Error Resume Next
appAccess.OpenCurrentDatabase strDBName
Set fil = fso.GetFile(strDBName)
If fil Is Nothing Then
strPrompt = “Can’t find “ & strDBName & _
“; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
Quit
NOTENOTE
Creating Standalone Scripts with Windows Script Host 17