You can create and run Visual Basic for Applications (VBA) macros to simplify and automate routine tasks. With Reflection, you can:
How to Record a Macro When Using the Reflection Desktop Ribbon(1:14)
How to Record a Macro When Using the Reflection Desktop Classic Interface(2:31)
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
The steps depend on your user interface mode.
User Interface Mode |
Steps |
---|---|
Reflection Ribbon |
On the Macros tab, from the Advanced group, click Run Macro. |
Reflection Browser |
On the Reflection menu, choose Tools, Macro and then Run Macro. |
TouchUx |
Tap the Wrench icon and then under Macro, select Show Run Macro Dialog. |
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: |
|
|
Select |
To show macros in |
|
<All Standard> |
All open projects and session documents. |
|
Common |
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). |
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
In Reflection, open a session document.
The steps depend on your user interface mode.
User Interface Mode |
Steps |
---|---|
Reflection Ribbon |
From the Macros tab, click Visual Basic. |
Reflection Browser |
On the Reflection menu, choose Tools, Macro and then Visual Basic. |
TouchUx |
Tap the Wrench icon and then under Macro, select Visual Basic. |
The session document appears as a project in the Project Explorer; for example, Project (My Session.rd3x).
In the Project Explorer, select the project in which you want save the macro, and then choose Insert > Module to create a new module.
Double-click the module you created.
The Code window opens.
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.
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.
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
The steps depend on your user interface mode.
User Interface Mode |
Steps |
---|---|
Ribbon |
On the Macros tab, from the Advanced group, click Record VBA. |
Reflection Browser |
On the Reflection menu, choose Tools, Macro and then Record VBA Macro. |
TouchUx |
Tap the Wrench icon, and then under Macro, select Record VBA Macro. |
Perform the task(s) that you want to automate.
(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.
When you are finished recording the macro, click Stop Recording.
The Recording Complete dialog box appears.
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.
Use the Visual Basic Editor to edit Reflection macros.
To edit a macro
The steps depend on your user interface mode.
User Interface Mode |
Steps |
---|---|
Reflection Ribbon |
From the Macros tab, click Visual Basic. |
Reflection Browser |
On the Reflection menu, choose Tools, Macro and then Visual Basic. |
TouchUx |
Tap the Wrench icon and then under Macro, select Visual Basic. |
The Macros dialog box appears.
In the Macro name box, select the name of the macro to edit and click Edit.
In the Visual Basic Editor, type in or edit the macro commands.
From the File menu, choose Save.
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
The steps depend on your user interface mode.
User Interface Mode |
Steps |
---|---|
Ribbon (Office 2007) |
On the Reflection button , choose Reflection Workspace Settings. |
Ribbon (Office 2010) |
On the File menu, choose Reflection Workspace Settings. |
Reflection Browser |
On the Reflection menu, choose Settings and then Reflection Workspace Settings. |
TouchUx |
Tap the Gear icon and then select Reflection Workspace Settings. |
Under Workspace Settings, click Configure Workspace Settings.
Under Workspace and Documents, in the When starting workspace list, select Run Startup action.
Click Select Action.
Under Action, select Run Reflection Workspace Macro.
Under Action parameters, choose Select macro.
In the Select a macro box, select the macro you want to run when Reflection starts.
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
The steps depend on your user interface mode.
User Interface Mode |
Steps |
Ribbon or Reflection Browser |
With a session open in Reflection, from the Quick Access Toolbar, click . |
TouchUx |
Tap the Gear icon and then select Document Settings. |
On the Settingsā¦ dialog box, do one of the following
(VT)click Configure Connection Settings.
(3270 or 5250), click Configure Advanced Connection Settings.
Under Connection Action, select whether to run the macro before or after the initial connection.
Click Select Action and select the macro to run.
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.)