VBA, and its subset version VBScript, is Microsoft's
technology for writing your own programs, both those that run in other
programs (scripts) and those that run by themselves (custom
applications). InDesign works with both VBA and VBScript. The Visual
Basic language that underlies both VBA and VBScript is not meant for
everyday computer users; knowledge of programming is very useful in
taking advantage of this technology. Although based on the Basic
language developed in the 1970s to help new users write their own
programs, it has evolved a lot since then and is no longer so simple.
1. Learning the language
Many of the actions specified in VBA have some degree of English, such as:
set myTextFrame = InDesign.Documents.Item(1).Spreads.Item(1).
TextFrames.Add
or
mySelection.RotationAngle = 30
As you can see, that degree
of English is slight. The first code segment, for example, means to add
a text frame to the first spread in the first document. The second
means to rotate the selected object by 30 degrees.
2. What you need to write and run scripts
To use InDesign scripting in
Windows, you need Microsoft Visual Basic or an application that
contains VBA; these include Microsoft Office, Microsoft Visio, and
AutoCAD. In Microsoft Office, you can run the Microsoft Script Editor by
choosing Tools => Macro => Microsoft Script Editor, which lets you create scripts, edit them, test your code, and fix errors. Figure 1
shows the editor with a sample script. (Note that the script editor's
dialog box has the self-important name Microsoft Development Environment
rather than Microsoft Script Editor.)
Before you venture too far
into scripting, you should review the VBA-related information provided
by Microsoft and with InDesign:
Microsoft scripting documentation and tools:
Microsoft has a lot of information on VBA, VBScript, and Visual Basic
on its Web site. Unfortunately, it's not well organized and thus is hard
to find and understand. There's no tutorial that simply explains how a
new scripter needs to get started. However, you can search on the
Microsoft site for VBA, VBScript, and Visual Basic to get links to
documents that may prove useful. InDesign scripting documentation:
The InDesign DVD contains a 2,000-plus-page PDF file that explains
scripting in InDesign, including VBA programming. This document,
although definitely on the technical side, is a valuable resource. It
includes an overview of VBA scripting and the object model, as well as a
list of InDesign-specific scripting terms and scripting examples.
|
You can also write scripts in
VBScript, a VBA subset, in a text editor such as WordPad. You need
Microsoft's free Windows Scripting Host (WSCRIPT.EXE), which is usually installed with Windows, and you can download it from Microsoft's Web site.
There's a third choice for your scriptwriting: You can also use the full Microsoft Visual Basic product.
NOTE
To use InDesign scripting in Windows, your user profile must have Administrator privileges.
To see what Visual Basic
commands InDesign supports, you can view the InDesign object model — the
supported commands — within the Microsoft's Visual Basic product; just
choose Project => References and then select Adobe InDesign CS5 Type Library in the References dialog box and click OK.
|
|
2.1. Running your script
There are a few ways to run a
VBScript. You can double-click the script in the Scripts panel within
InDesign or double-click the script file itself from a folder. When
developing scripts, you can run the script directly from the application
in which you created a VBA or Visual Basic script, such as the
Microsoft Script Editor. (VBScripts can be run from the Scripting Host
application.) In all these cases, InDesign becomes the active program,
and your script is running.
2.2. Saving your script
When you're finished
writing and testing a script, choose Save from the script editor's File
menu. Name your script and choose its storage location.