Share via


Writing VBScript Macros by Hand

Home Page (Macros)OverviewHow Do I TopicsFAQReference

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

  1. On the Tools menu, click Macro.

  2. 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.

  3. In the Macro Name box, enter a new name for the macro.

  4. 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.

  5. 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, the Sub 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