InfoConnect VBA Guide
Quickstart / Open a Session From a Microsoft Excel Macro
In This Topic
    Open a Session From a Microsoft Excel Macro
    In This Topic

    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.

    If you prefer to run macros in pre-configured sessions instead of creating your own sessions, you can download the VBA Sample Sessions and open the open-ibm-session-from-excel.xlsm (IBM) and open-os-session-from-excel.xlsm (Open Systems) files. The download package contains everything you need to run the macros in these files. See Download the VBA Sample Sessions.

    Open an 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 initializes
              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:

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

    See Also