Reputation: 5
My company recently upgraded from Attachmate EXTRA! to Attachmate Reflection. We have a number of macros that ran on extra to screen scrape. Basically, you would press a button to start the macro, it would ask you to select which extra screen you wanted to run it on (we always have 3+ open for different systems), and then the macro would just use the most recently selected (active) session. Here's the code for that:
Private Function GetReflectionWindow(sessionName As String) As ExtraScreen
'Gets the most recent active reflection or extra window.
'Requires Reference: EXTRACOM
Dim sys As ExtraSystem: Set sys = CreateObject("EXTRA.System")
Dim sess As ExtraSession
'Set current sesion to most recently active session
If MsgBox("Click on the " & sessionName & " session and click 'OK' to continue.", vbOKCancel) = vbCancel Then End
Set sess = sys.ActiveSession
'Checks the session
If sess Is Nothing Then
MsgBox "Could not locate a Reflection or Extra session!", vbCritical
End
Else
Set GetReflectionWindow = sess.Screen
sess.Activate
End If
End Function
This no longer works for Reflection systems. Instead I've looked at this documentation here. The problem is that when you use CreateObject or GetObject, it only looks at the first open instance, not the active instance.
Sub GetNewReflectionWindow()
Dim App As Attachmate_Reflection_Objects_Framework.ApplicationObject
Dim screen As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmScreen
Dim Terminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmTerminal
Dim Frame As Attachmate_Reflection_Objects.Frame
Dim View As Attachmate_Reflection_Objects.View
Set App = GetObject(, "Attachmate_Reflection_Objects_Framework.ApplicationObject")
End Sub
I can't see anything in the documentation or object browser that would let me select the active session like Extra.System did.
Upvotes: 0
Views: 1737
Reputation: 132
I had the same issue and finally found the solution in the MicroFocus docs of all places! Accessing All Open "Reflection Workspace" Objects in VBA Macro Code
Basically, continue to use CreateObject to get the Workspace, but do it in a loop renaming each one as you go:
Dim oSession As Object
'find all open sessions
Do
Set oSession = CreateObject("Reflection Workspace")
oActiveSession.AutomationServerName = "Unused"
Loop
'rename sessions back to original
Do
Set oActiveSession = CreateObject("Unused")
oActiveSession.AutomationServerName = "Reflection Workspace"
Loop
I put this into its own function as the CreateObject throws an error when you run out of Workspaces.
Upvotes: 0