This example shows how to create a macrothat gets text from the screen and displays it in a message box.
This article contains tabbed content that is specificto eachterminal type. Be sure the tab for yourWhich Terminal Type are you Using? is selected.
Create a macro
On the Tools tab,selectVisual Basic to open the Visual Basic Editor.
In the Visual Basic Project Explorer,right click onthe 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 SubCopyTextMacro().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, seeNaming Macros.
Enter the code for the macro in your new subroutine as shown below and then save your new macro.
IBM
Open Systems
Get text from the screen
Copy Code
Sub CopyTextMacro() 'Create a variable to hold the textDim screenText AsString'Get text from the screen starting at screen row 1, column 1, and 30 characters long screenText = ThisIbmScreen.GetText(1, 1, 30) 'Display the text in a message boxMsgBox (screenText )End Sub
Get text from the screen
Copy Code
Sub CopyTextMacro() 'Create a variable to hold the textDim screenText AsString'Get text from the screen starting at screeen column 1, row 1' and ending at row 30, column 30 screenText = ThisScreen.GetText2(1, 1, 30, 30) 'Display the text in a message boxMsgBox (screenText )End Sub
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.)
Concepts
This macro uses an InfoConnect property (ThisScreen for Open Systems or ThisIbmScreen for IBM) togetthe screen object for the session. You can use this property to get the screen object for any macro in a session project.InfoConnect provides several other properties that you can use toget key objects when you are creating macros in session projects.For more about these properties, seeUsing the InfoConnect Object Model.
The screenobject represents the host application screen andit provides methods and properties used to access host screen data.The GetText methodused in the IBM sampleis 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 libraryGetTextEx method can be usedfor the same purpose.
In the Code group on the Developer tab, click Record Macro.
Optionally, enter a name for the macro in the Macro name box, enter a shortcut key in the Shortcut key box, and a description in the Description box, and then click OK to start recording.
To access the VBA editor in Excel, first, ensure the Developer tab is visible. If it's not, click File > Options and select Customize Ribbon. Then, check the box next to Developer in the right pane. Now, click the Dev tab and select Visual Basic or use the shortcut Alt + F11 to open the VBA editor.
Visual Basic for Applications is a computer programming language developed and owned by Microsoft. You can create macros to automate repetitive word- and data-processing functions with VBA and generate custom forms, graphs, and reports. VBA functions within MS Office applications.
Macro code refers to the VBA (Visual Basic for Applications) code for the macro. You can create macros in Excel by either recording the steps you want it to perform (the VBA is written for you), or by writing the VBA yourself. Writing this VBA or macro code yourself gives you far greater control over your macro.
1. Macro Is the peace of code or recorded steps of user activity whereas VBA(Visual Basic For Application) is a programming language. 2. Excel Macros are recorded in VBA so we can say that VBA is a wider term which includes macros.
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.
Open your workbook in Excel. Press Alt + F11 to open Visual Basic Editor (VBE). Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window) and select Insert -> Module from the context menu.
Excel VBA is Microsoft's programming language for Office applications such as MS-Excel, MS-Word, and MS-Access. Macros are what most people who write VBA code use.
Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379
Phone: +2678139151039
Job: International Administration Supervisor
Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports
Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.
We notice you're using an ad blocker
Without advertising income, we can't keep making this site awesome for you.