Exporting Host Screen Data to Excel Using a Macro
Flex Terminal Emulator allows you to automate the extraction of data from host screens and export it directly into an Excel spreadsheet using a macro. This approach is useful for collecting structured data across multiple screens.
Overview
A macro can be used to:
Extract specific data fields from the current host screen
Write the data to an Excel spreadsheet
Navigate to the next host screen
Repeat the process for multiple screens
Sample Macro Code
The following example demonstrates how to retrieve data from defined screen positions and export it into Excel:
- Sub Main()
- ' Create the Excel objects
- Set objExcel = CreateObject("Excel.Application")
- objExcel.Visible = true
- Set objWorkbook = objExcel.Workbooks.Add
- nRow = 1
- nCol = 1
- For i = 1 to 4
- objExcel.Cells(nRow, nCol).Value = FlexScreen.GetText (FlexScreen.Position(4, 2), 6)
- objExcel.Cells(nRow, nCol+1).Value = FlexScreen.GetText (FlexScreen.Position(4, 10), 20)
- objExcel.Cells(nRow, nCol+2).Value = FlexScreen.GetText (FlexScreen.Position(4, 31), 8)
- objExcel.Cells(nRow+1, nCol).Value = FlexScreen.GetText (FlexScreen.Position(5, 2), 6)
- objExcel.Cells(nRow+1, nCol+1).Value= FlexScreen.GetText (FlexScreen.Position(5, 10), 20)
- objExcel.Cells(nRow+1, nCol+2).Value= FlexScreen.GetText (FlexScreen.Position(5, 31), 8)
- objExcel.Cells(nRow+2, nCol).Value = FlexScreen.GetText (FlexScreen.Position(6, 2), 6)
- objExcel.Cells(nRow+2, nCol+1).Value= FlexScreen.GetText (FlexScreen.Position(6, 10), 20)
- objExcel.Cells(nRow+2, nCol+2).Value= FlexScreen.GetText (FlexScreen.Position(6, 31), 8)
- objExcel.Cells(nRow+3, nCol).Value = FlexScreen.GetText (FlexScreen.Position(7, 2), 6)
- objExcel.Cells(nRow+3, nCol+1).Value= FlexScreen.GetText (FlexScreen.Position(7, 10), 20)
- objExcel.Cells(nRow+3, nCol+2).Value= FlexScreen.GetText (FlexScreen.Position(7, 31), 8)
- ' Move to the next host screen
- Ok = FlexScreen.SendKeys(FlexKey.PF1)
- Ok = FlexScreen.WaitForNoX()
- nRow = nRow + 4
- Next
- End Sub
How It Works
The macro creates and opens a new Excel workbook.
It reads data from specific positions on the host screen using FlexScreen.GetText.
Extracted values are written into Excel cells row by row.
After collecting data from one screen, it sends the PF1 key to navigate to the next screen.
This process repeats for a defined number of screens.
Notes and Customization
The sample assumes:
4 rows of data per screen
3 columns of data per row
Fixed screen positions for each field
The loop For i = 1 to 4 determines how many screens are processed.
Modify the screen coordinates (Position(row, column)) and field lengths to match your application’s layout.
You can change the navigation key (PF1) if your host uses a different key to advance screens.
Saving and Using the Macro
To use this macro in your environment:
Copy the sample code into the Flex Terminal Emulator macro editor, or any text editor (such as Notepad).
Save the file with a .ams extension.
Place the file in the Macros subfolder of your Flex Terminal Emulator user directory.
Run the macro from within Flex Terminal Emulator.
This method provides a powerful way to automate data collection and eliminate manual data entry when working with multiple host screens.
Related Articles
Exporting a Host Screen to Microsoft Word
Flex Terminal Emulator allows you to export the contents of a host screen directly into a Microsoft Word document using a macro. This is useful for documentation, reporting, or sharing screen data. Overview The macro performs the following actions: ...
Exporting a Host Screen to an Outlook Email
Flex Terminal Emulator allows you to export the contents of a host screen directly into a new Microsoft Outlook email using a macro. This is useful for quickly sharing or documenting screen data. Overview The macro performs the following actions: ...
Recording a Login Macro and Running It Automatically at Startup
Flex Terminal Emulator allows you to automate the login process by recording a macro and configuring it to run each time a session connects to the host. Step 1: Record a Login Macro Follow these steps to capture your login sequence: Open the Flex ...
Maximizing the Host Screen Area in Flex Terminal Emulator
To increase the visible host screen area in Flex Terminal Emulator, you can hide or minimize certain interface elements. The following options can help you optimize screen space. Hide the Status Bar The Status Bar is displayed at the bottom of the ...
Supported Host Code Pages in Flex Terminal Emulator
Flex Terminal Emulator supports a range of host code pages to ensure compatibility with different regional and language requirements. Available Host Code Pages The following host code pages are supported: 037 – US / Canada 273 – Austria / Germany 277 ...