Open a Session From a Microsoft Excel Macro

You can open an InfoConnect session from another application that supports VBA.

Visual Basic uses a standard set of protocols called Automation (or OLE Automation) that allows one application to communicate with other applications. Any application that supports Automation can communicate with any other application. This means that an InfoConnect session can communicate with other InfoConnect sessions, Microsoft Office products, stand-alone Visual Basic, or any other product that supports Automation.

This example shows how to open an InfoConnect session document from an Excel macro.

Open a InfoConnect session from an Excel Macro

  1. In InfoConnect, create a session and save it as "mySavedSession" in your  ...\Documents\Micro Focus\InfoConnect\" folder.
  2. In a Microsoft Excel worksheet, open the Visual Basic Editor and insert a new code module.  
  3. On the Excel VBA Editor Tools menu, select References and then select the following InfoConnect Libraries:
    • Attachmate_Reflection_Objects
    • Attachmate_Reflection_Objects_Emulation_IbmHosts (if you want to open an IBM session)
    • Attachmate_Reflection_Objects_Emulation_OpenSystems (if you want to open an Open Systems session)
    • Attachmate_Reflection_Objects_Framework
  4. Copy the following code into the VBA Editor and press F5 to run it.
    Open a session
    Copy Code
    Private Sub OpenReflectionIBMSession()
        'Declare an object variable for the InfoConnect 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 InfoConnect is open, get a handle to it
        On Error Resume Next
        Set app = GetObject("InfoConnect Workspace")
    
        'Otherwise, create a new instance of InfoConnect     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 InfoConnect 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\InfoConnect\" & "mySavedSession.rd3x") 
    
        'Create a view so that we can display the session
        Set view = frame.CreateView(terminal)
    End Sub 
    
    Open a session
    Copy Code
    Private Sub OpenReflectionOpenSystemsSession()
        'Declare an object variable for the InfoConnect 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_OpenSystems.terminal
        Dim view As Attachmate_Reflection_Objects.view
           
        'If an instance of InfoConnect is already open, get a handle to it
        On Error Resume Next
        Set app = GetObject("InfoConnect Workspace")
    
        'Otherwise, create a new instance of InfoConnect     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 InfoConnect is initialized
            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 Open Systems terminal control using an .rdox sesssion document file
        Set terminal = app.CreateControl(Environ$("USERPROFILE") & _
        "\Documents\Micro Focus\InfoConnect\" & "mySavedSession.rdox")
          
        'Create a view so that we can display the session
        Set view = frame.CreateView(terminal)
    End Sub
    

Concepts

To open a session from another application, you'll need to use the InfoConnect ApplicationObject, IbmTerminal or Terminal, Frame, and View objects:

  • The ApplicationObject is the InfoConnect application.
  • The Frame object is the top-level user interface component for the workspace and it can be used to control the display of the workspace and to create views for the terminal controls running in the workspace.
  • The IbmTerminal (or Terminal) object is the top level control for the new session. The CreateControl method returns the appropriate terminal control for the session document file that you pass to it.
  • The View object represents the user interface aspect of the new session. To display the session, we need to create a View Object for the terminal and we do this using the Frame object.

For more about these objects, see Using the InfoConnect Object Model.

See Also