3.6 Record, Run, and Edit VBA Macros

3.6.1 Run a Macro

You can run VBA macros created in Reflection, and most macros created with legacy Reflection and EXTRA! products. You can also run the majority of macros created with the Micro Focus Rumba, IBM Personal Communications, OpenText HostExplorer, and Brandon Systems\Jolly Giant QWS3270 products. However, you can only run macros in trusted locations.

Several macro-related actions (such as, Run a Reflection Workspace Macro) are available from the Select Action dialog box.

You can also run a macro by mapping an action to a control. For more information, see Add a Button to Run a Macro.

To run a macro

  1. From the Run Macro dialog box, select the macro you want to run.

    NOTE:Legacy macro options are available only if compatibility features are installed. In addition, to run legacy Reflection and EXTRA! macros from external files, you must specify, from the Set Up API and Macro Security dialog box, the type of legacy macro you want to run.

    Reflection Workspace Macro

    Shows macros in the active session document. Select to run macros created in Reflection or 2007 (SP1) documents.

    To run a macro in the Common project and other documents, select one of the following options from the Macros in menu:



    To show macros in


    <All Standard>

    All open projects and session documents.



    The Common project.


    Project [ > filename > ]

    The active session document only.

    Legacy Reflection Macro in This File

    Select to run legacy macros in the active document. These macros include legacy settings files (.rsf, .r2w, or .r4w), and in Reflection, session documents (.rd3x, .rd5x, .rdox) that were previously converted from settings files.

    Legacy Reflection Macro in Another File

    Select to specify and run a macro in a SharedMacro file (.rma) or a settings file (.rsf, .r2w, or .r4w).

    Legacy RB Macro

    Select to specify and run a Reflection Basic macro (.rbs).

    Legacy RCL Script

    Select to specify and run a legacy RCL script. Available only for use in VT session documents.

    Legacy EXTRA! Macro

    Select to specify and run an EXTRA! macro file (.ebm).

    Rumba Macro

    Select to specify and run a Micro Focus Rumba macro file (.rmc).

    QWS Macro

    Select to specify and run a Brandon Systems\Jolly Giant QWS3270 macro file (.jgs).

    IBM Personal Communications Macro

    Select to specify and run an IBM Personal Communications macro file (.mac).

3.6.2 Create a Macro in the Visual Basic Editor

Whenever possible, create macros in Modules. Doing so will add to the integrity and stability of your program. The exception to this rule is event procedures, which are added directly to Reflection objects.

To create a macro in the Visual Basic Editor

  1. In Reflection, open a session document.

  2. The session document appears as a project in the Project Explorer; for example, Project (My Session.rd3x).

  3. In the Project Explorer, select the project in which you want save the macro, and then choose Insert > Module to create a new module.

  4. Double-click the module you created.

    The Code window opens.

  5. Choose Insert > Procedure, type a name in the Name box, and then click OK.

    The name you choose must follow the Visual Basic naming conventions for macros. For further information, see Naming Macros.

  6. Type code for your macro between the Sub (or Public Sub) and End Sub statements.

    Context-sensitive Help is available for Visual Basic commands. Position the insertion point within a command and press F1.

3.6.3 Record a VBA Macro

You can record a VBA macro to automate your interaction with host applications, including:

  • Sending data to, or typing text in, a host application.

  • Cutting, copying, or pasting text or data from one host application to another.

  • Switching tabs to move from one host application to another.

  • Selecting text with a mouse or clicking the mouse to move the cursor (mouse clicks are recorded as cursor positions.)

You cannot record:

  • Interaction with Reflection settings and Productivity features (such as Spell Check, Auto Expand, and Auto Complete).

  • Connecting to or disconnecting from a host.

  • Interaction with Web applications.

  • Cutting or pasting from a host to an external application (for example, Notepad).

To record a macro

  1. Perform the task(s) that you want to automate.

  2. (Optional) If you need to interrupt the recording to perform another task, click Pause Recording. When you are ready to resume recording, click Pause Recording again.

  3. When you are finished recording the macro, click Stop Recording.

    The Recording Complete dialog box appears.

  4. Name the macro, choose the location where you want to save it, and then click OK.

    NOTE:You can fine-tune recorded macros by using the Visual Basic Editor. For more information, see see Edit a Macro.

3.6.4 Edit a Macro

Use the Visual Basic Editor to edit Reflection macros.

To edit a macro

  1. The Macros dialog box appears.

  2. In the Macro name box, select the name of the macro to edit and click Edit.

  3. In the Visual Basic Editor, type in or edit the macro commands.

  4. From the File menu, choose Save.

3.6.5 Run a Startup Macro

You can set up a Visual Basic for Applications (VBA) macro to run when a Reflection workspace starts, rather than when a session opens and connects to the host.

This allows you to gather information about how users will connect and then use that information to configure session settings.

For example, you can create a startup macro to perform tasks such as:

  • displaying a VBA UserForm to gather information from the user before connecting to the host

  • reading from an .ini file

  • checking for host or router availability

  • configuring Reflection settings

    CAUTION:You can configure only macros in the Common project to run when the workspace starts. Do not configure the "Run Reflection Workspace Macro" action to run a macro present in a session document (rd0x, rd3x, rd5x). This prevents Reflection from starting properly.

To set up a startup macro

  1. Under Workspace Settings, click Configure Workspace Settings.

  2. Under Workspace and Documents, in the When starting workspace list, select Run Startup action.

  3. Click Select Action.

  4. Under Action, select Run Reflection Workspace Macro.

  5. Under Action parameters, choose Select macro.

  6. In the Select a macro box, select the macro you want to run when Reflection starts.

3.6.6 Set up Macros that Run Before or After a Host Connection

If you have created a macro for your session or workspace, you can set up the session to run a connection macro.

To set up a connection macro

  1. On the Settingsā€¦ dialog box, do one of the following

    • (VT)click Configure Connection Settings.

    • (3270 or 5250), click Configure Advanced Connection Settings.

  2. Under Connection Action, select whether to run the macro before or after the initial connection.

  3. Click Select Action and select the macro to run.

3.6.7 Naming Macros

Observe the following rules when you name Visual Basic macros (including procedures, constants, variables, and arguments):

  • Use a letter as the first character. (Names aren't case sensitive, but they preserve capitalization.)

  • Use only alphanumeric characters and the underscore character ( _ ). Spaces and other symbols are not allowed.

  • Use fewer than 255 characters.

  • Avoid names that match Visual Basic or Reflection commands. Or, if you do use a macro name that is the same as a command, fully qualify the command when you want to use it. (To do this, you need to precede the command name with the name of the associated type library. For example, if you had a macro named Beep, you could only invoke the Visual Basic Beep statement using VBA.Beep.)

  • Give unique names to macros within a single module. Visual Basic doesn't allow you to have two macros with the same name in the same code module. However, you can have two macros with the same name if they are in different code modules. For example, although you could not have two macros named StartUp in the same code module, you could have two macros named StartUp if they were in different code modules. To call a macro with a duplicate name that is in another code module, you must fully qualify the macro name. (For example, Module1.StartUp invokes the StartUp macro in Module1.)