
Technical Notes |
|
When attempting to use a Reflection Workspace macro that was recorded in Reflection 2011, 2008, or 2007, the following error may be displayed: "Compile error: User-defined type not defined." This technical note explains the cause of this error and provides a workaround.
When you record a VBA (Visual Basic for Applications) macro, it can be saved to the session document (.rd0x, .rd3x, or .rd5x file) or to the Common project.
This error occurs when a recorded Reflection Workspace macro is run from the common project area. Recorded macros typically contain session object information, which is not supported in the Common project.
To resolve this error, do one of the following:
Rerecord the macro and save it to the current document's project, rather than the common project area. Note: Macros saved to the current document's project are available only when the current session is loaded.
To record a macro, follow these steps.
Usually the Common project is for macro code that is not session-specific or can be used by any session. However, if you wish to make the recorded session macro work when saved to the common area, add a reference to the appropriate session object library.
Follow the steps below to edit the macro and add a reference to the Attachmate Reflection library.
With this library selected, the macro will now run without the compile error as long as the session indicated in the macro currently has Windows focus.
To make your macro run the specified session is open (regardless of whether the session has Windows focus), edit the "set currentTerminal=" line.
Set currentTerminal = ThisFrame.SelectedView.controlSet currentTerminal = ThisFrame.GetViewByTitleText("Name.rd5x").controlwhere "Name.rd5x" is your session name.
Sample macro with edits made:
Sub tinymacro() Dim currentScreen As IbmScreen Dim currentTerminal As IbmTerminal Dim frame As frame Dim viewList() As View Dim hostSettleTimeout As Integer Dim hostSettleTime As Integer hostSettleTimeout = 2000 hostSettleTime = 500 Set viewFrame = Application.GetObject("Frame") ‘ This line commented out: ‘Set currentTerminal = ThisFrame.SelectedView.control ‘ This line inserted: Set currentTerminal = ThisFrame.GetViewByTitleText("Name.rd5x").control Set currentScreen = currentTerminal.Screen currentScreen.SendKeys ("1") currentScreen.SendControlKey (ControlKeyCode_CMD_TRANSMIT) rv = currentScreen.WaitForHostSettle(hostSettleTimeout, hostSettleTime) End Sub |
The macro will now run without the compile error regardless of which Window has focus as long as the session with the name indicated in the "set currentTerminal=" line is opened (Name.rd5x in the example above).