Writing VBScript Macros by Hand
Home Page (Macros) | Overview | How Do I Topics | FAQ | Reference
You can write a VBScript macro manually by adding the code for the macro to a new or existing macro file.
To write a macro by hand
On the Tools menu, click Macro.
To add the macro to a new macro file, click the Options button, click the New File button, and then enter a name for the file, the path to the file, and a description of the file.
-or-
To add the macro to an existing file, select the file name in the MacroFile box. If the name is not in the list, first install the file, then select it in the MacroFile box.
In the Macro Name box, enter a new name for the macro.
Click the Edit button.
Note You cannot create a new macro in a read-only file, but you can browse an existing macro in a read-only file.
In the AddMacro dialog box, enter a description of the macro, and then click OK.
Visual C++ opens the macro file, creates a
Sub
block (macro stub) for the new macro at the end of the file. For example, if the macro name were MyMacro, theSub
block would look like:Sub MyMacro() 'Description: The macro description goes here. 'TODO: Insert the macro code here. End Sub
Tip It is good practice to declare variables used in a macro. You declare variables by using the VBScript Dim statement. You can be sure to declare variables before using them by adding the line, "Option Explicit" at the beginning of a macro file. For more information about the VBScript language, see the .
See Also Recording VBScript Macros