How to make recorded VBA macros "agnostic" or able to run against any host screen

  • 7024221
  • 29-Oct-2019
  • 31-Oct-2019

Environment

Reflection Desktop (including Pro, for X, for IBM, or for UNIX and OpenVMS) 16.0 or higher

Situation

This technical article describes how to make recorded VBA macros "agnostic" or how to give the macro the ability to be to run against any host screen.  Recorded VBA macros are typically designed to be run against a very specific host screen or set of host screens, but sometimes it is desirable to modify these macros so that they can be run against a variety of different host screens.  Sometimes users want simple macros which can be run from keyboard shortcuts or buttons on a toolbar or ribbon and be run against any host screen.

Resolution

To accomplish this, remove all the error checking from the recorded VBA macros so the macro will only send the commands or keys and does not do any error checking.  There are risks of removing the error handling but for simple commands these risks are minimal.  Writing a new macro from scratch is sometimes the best way to proceed, but users who are unfamiliar with VBA can use recorded macros which they can edit themselves.

Manually edit the recorded macro in the Visual Basic Editor and remove (comment out) the following types of VBA commands by adding an apostrophe at the beginning of each line.   Typically these will be WaitForCursor, WaitForText, and WaitForString types of commands.

For IBM sessions:
    Remove:
    'Wait for cursor to be in position before continuing
    returnValue = ibmCurrentScreen.WaitForCursor1(timeout, 24, 2)
    If (returnValue <> ReturnCode_Success) Then
        Err.Raise 5001, "WaitForCursor1", "Timeout waiting for cursor position.", "VBAHelp.chm", "5001"
    End If

    waitText = "===>"
    returnValue = ibmCurrentScreen.WaitForText1(timeout, waitText, 8, 15, TextComparisonOption_MatchCase)

For Unix and OpenVMS sessions:
    Remove:
    'Wait for a string on the host screen before continuing
    returnValue = osCurrentScreen.WaitForString3(NUL & "$ ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
    If (returnValue <> ReturnCode_Success) Then
        Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
    End If

Feedback service temporarily unavailable. For content questions or problems, please contact Support.