How to present macro output as an HTML document using Reflection VBA

  • 7023229
  • 31-Jul-2018
  • 22-Aug-2018


Reflection Desktop (including Pro, for X, for IBM, or for UNIX and OpenVMS) 16.0 and later
InfoConnect Desktop (including Pro, for Unisys, for Airlines) 16.0 and later


Reflection (and InfoConnect) Desktop both include an embedded version of Microsoft Internet Explorer. In addition to providing quick access to websites directly in the Reflection Workspace environment, the Reflection Web Browser can also be used to display reports or other types of output that can be generated using Reflection VBA macros. This example explains how to use a macro to launch a new web browser tab in the Reflection Workspace, then collect data from the terminal session and display it as HTML in a Reflection web browser tab.


  1. Create and save a new Reflection mainframe or iSeries session (*.rd3x or *.rd5x).
  2. Connect the session to your host system.
  3. Open the Reflection Visual Basic Editor (...on the ribbon's "Macros" tab).
  4. In the "new" project (not the "legacy" project), insert a new VBA module.
  5. Copy the Visual Basic code below to the new module. Save.
  6. When this code is run, it will display the current screen in a new WebControl tab.
  7. Note: This example can easily be adapted for use with a Unix or Unisys session.
  8. Note: This example won't work if Reflection's "Web Browser" feature has not been installed.
' CreateReportInBrowser
' This example demonstrates how you might use Reflection's built-in web browser
' capabilities to display a custom report that contains data from the current
' terminal screen. Generating output this way could be a convenience in many
' situations, and certainly gives you plenty of flexibility with formatting, etc.
' In this example, a new Reflection WebControl is created, then the current
' IbmTerminal display is written out as an html document. In a real-life situation,
' you could go on collecting specific information from multiple screens, adding
' it to an html table or anything else you can imagine before showing it...
' In an .rd3x or .rd5x session file, add this code to a new module in the
' Reflection Visual Basic Editor.
' Example code provided without warranty or support.
' Please review and understand it before running.
Sub CreateReportInBrowser()
    Const WebControlGUID = "{F1F058B1-0472-4095-A782-3D7333813AD0}"

    'First, build an HTML string containing the report to be presented...
    'in this case, just copy the current screen text.
    Dim html As String
    html = "<head></head><body>"
    html = html & "<div style=""font-family:monospace;font-size:12pt;white-space:pre"">"
    'add each row from the display to html output...
    Dim i As Integer
    For i = 1 To ThisIbmScreen.rows
        html = html & ThisIbmScreen.GetText(i, 1, ThisIbmScreen.columns)
        html = html & "<br>"
    'Finish the html...
    html = html & "</div></body>"

    Dim webctrl As WebControl
    Dim newview As View
    'Create a new Reflection WebControl, based on GUID value (see help).
    'Then create a new Reflection View to host the new WebControl.
    Set webctrl = Application.CreateControl2(WebControlGUID)
    Set newview = ThisFrame.CreateView(webctrl)
    'Must wait for the WebControl to be ready before doing anything.
    Do While webctrl.ReadyState <> WebBrowserReadyState_Complete
    'Get the Document object from the WebControl, then
    'get the main HTML element from the Document.
    Dim webdoc As WebDocument
    Set webdoc = webctrl.Document
    Dim htmlElem As WebElement
    Set htmlElem = webdoc.GetElement("HTML")
    'Put the custom html we collected inside the HTML element.
    htmlElem.InnerHtml = html
    'When closing the WebControl tab, there will be a prompt to save
    'the new .urlx document just created. If you want to avoid making people
    'click on that, save the .urlx for them. Note: only URL information
    'is saved to the .urlx document, not the HTML content written.
    Dim rc As ReturnCode
    rc = webctrl.SaveAs(Environ("USERPROFILE") & "\documents\Micro Focus\Reflection\url.urlx")
    If rc <> ReturnCode_Success Then
        MsgBox "urlx SaveAs error!"
    End If

    'Set the title on the new View (tab).
    newview.titleText = "Macro output"  

End Sub

Additional Information

Example mainframe screen:

Example result...
You can collect any data from terminal screens and present it with any HTML formatting desired.

Another is a typical listing of mainframe data:

In this case, the macro paged down collecting ten screens of data, then presented it as a formatted html table. In a real-life solution, each item in a listing like this might include a link to some sort of further information.