Technical Note 2210
Last Reviewed 20-Jul-2010
Reflection for IBM 2014
Reflection for UNIX and OpenVMS 2014
Reflection for IBM 2011
Reflection for UNIX and OpenVMS 2011
Reflection Standard Suite 2011
When attempting to use a Reflection Workspace macro that was recorded in Reflection 2014, 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.
Resolving the Error
To resolve this error, do one of the following:
Save the Macro to the Session Document Project
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.
- In the Reflection Workspace, open or create a new terminal session.
- Click Record Macro.
- Perform the tasks you want to automate, and then click Record Macro again.
- In the Recording Complete dialog box, enter a Macro name.
- Select "Save in the current document's project."
Edit the Macro in the Common Project
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.
Add a Reference to the Attachmate Reflection Library
Follow the steps below to edit the macro and add a reference to the Attachmate Reflection library.
- Open the macro in the Visual Basic editor.
- Click Tools > References.
- Select Attachmate_Reflection_Objects_Emulation_IBMHosts or Attachmate_Reflection_Objects_Emulation_OpenSystems library, depending on your host type.
- Click OK.
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.
Running Macro Regardless of Session Focus
To make your macro run the specified session is open (regardless of whether the session has Windows focus), edit the "set currentTerminal=" line.
- Edit the macro in the Visual Basic editor.
- Scroll down to the following line:
Set currentTerminal = ThisFrame.SelectedView.control
- Delete this line, or comment it out by inserting an apostrophe character (') at the beginning of the line.
- Replace the line with the following code:
Set currentTerminal = ThisFrame.GetViewByTitleText("Name.rd5x").control
where "Name.rd5x" is your session name.
Sample macro with edits made:
- Click File > Save common.
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).