mercredi 28 octobre 2020

Excel Macro VBA Connection to Reflection Desktop to open a new Session

Im trying to automate a process in Reflection and am using the code from the attachmate site to open the connection:

Private Sub OpenReflectionIBMSession()
    'Declare an object variable for the Reflection application
    Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
    
    'Declare frame, terminal, and view object variables:
    Dim frame As Attachmate_Reflection_Objects.frame
    Dim terminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmTerminal
    Dim view As Attachmate_Reflection_Objects.view
 
    'If an instance of Reflection is open, get a handle to it
    On Error Resume Next
    Set app = GetObject("Reflection Workspace")

    'Otherwise, create a new instance of Reflection
    On Error GoTo 0
    If IsEmpty(app) Or (app Is Nothing) Then
       Set app = New Attachmate_Reflection_Objects_Framework.ApplicationObject
    End If
   
    With app
        'wait until Reflection initalizes
        Do While .IsInitialized = False
           .Wait 200
        Loop
       
       'Get a handle to the Frame object
        Set frame = .GetObject("Frame")
       
        'Make the frame visible so we can view the workspace
        frame.Visible = True
    End With
     
    'Create an Ibm3270 control using an .rd3x session document file
    Set terminal = app.CreateControl(Environ$("USERPROFILE") & _
    "\Documents\Micro Focus\Reflection\" & "mySavedSession.rd3x") 

    'Create a view so that we can display the session
    Set view = frame.CreateView(terminal)
End Sub 

When the execution reaches the line

Set terminal = app.CreateControl(Environ$("USERPROFILE") & _
    "\Documents\Micro Focus\Reflection\" & "mySavedSession.rd3x") 

I get a runtime error saying

Invoke or BeginInvoke cannot be called on a control until the window handle has been created

Any idea why this might be happening ? I tried everything and nothing seems to work. I get the same error when trying to create a new connection as well





Aucun commentaire:

Enregistrer un commentaire