Access.2007.VBA.Bibl..

(John Hannent) #1

F


or many versions now, Windows has had its own scripting language,
Windows Script Host, a dialect of Visual Basic Script (VBS). Windows
Script Host (WSH) scripts can be run from the command line (for
those versions of Windows that have a command line, click Start➪Run), by
double-clicking the script file in an Explorer window, and also from the
Windows Vista Task Scheduler, which is handy if you want to run a script
automatically, on a regular schedule.

One use for a WSH script is to create a database backup at regular intervals;
another is to copy Word or Excel templates, or other supporting files, to the
appropriate folder, as part of an Office application setup, when you don’t
want (or need) to create a full Install package. WSH scripts are also useful
for working with files in a folder, doing tasks such as deleting or renaming
files containing a certain prefix, suffix, or extension. This chapter describes
how to create and modify WSH scripts, including sample scripts for some
common uses.

Tools for Working with Windows Script Host Scripts ........................................................


Though you can create and edit WSH scripts with Notepad, it is a lot easier to
work with them in the Microsoft Script Editor (MSE), using the VBScript
downloadable Help file for reference. Curiously, neither the MSE nor the
VBScript Help file appears as part of the interface when you work with a WSH
script; you have to locate (and possibly download) these files and set them up
manually to provide a more functional working environment. The next sec-
tions tell you how to obtain and use these tools for working with WSH scripts.

IN THIS CHAPTER


Writing Windows Script Host
scripts

Using the Microsoft Script Editor
and the VBS Help file

Differences between VBS and
VBA code

Scripts for working with Office
documents

Scripts for working with files

Using the Windows Vista Task
Scheduler to run a backup script

Creating Standalone Scripts


with Windows Script Host

Free download pdf