Create a Macro with the VBA Editor
In This Topic
This example shows how to create a macro that gets text from the screen and displays it in a message box.
Create a macro
- On the Tools tab, select Visual Basic to open the Visual Basic Editor.
- In the Visual Basic Project Explorer, right click on the project folder, and choose Insert > Module.
- In the code window, add a subroutine by entering Sub followed by the name for the macro. For this example, enter Sub CopyTextMacro(). The editor creates the End Sub line.
The name you choose for the subroutine must follow the Visual Basic naming conventions for macros. For more information, see
Naming Macros.
- Enter the code for the macro in your new subroutine as shown below and then save your new macro.
- Place the cursor anywhere in the procedure (Sub) you just created and then press F5.
The message box should display the text on the first line. (If your screen doesn't have any text in the upper left part of the display area, you may need to change the row and column arguments and run the macro again to display some text.)
For information about editing Extra! or Reflection Basic macros, see Using Extra! and Legacy Reflection Macros.
Concepts
This macro uses a Reflection property (ThisScreen for Open Systems or ThisIbmScreen for IBM) to get the screen object for the session. You can use this property to get the screen object for any macro in a session project. Reflection provides several other properties that you can use to get key objects when you are creating macros in session projects. For more about these properties, see Using the Reflection Object Model.
The screen object represents the host application screen and it provides methods and properties used to access host screen data. The GetText method used in the IBM sample is used to get the text from a screen location. The Open Systems library also has a GetText method that you can use in the same way.
The GetText2 method used in the Open Systems sample is used to get the text in a region of the screen. The IBM library GetTextEx method can be used for the same purpose.
See Also