Reflection Desktop VBA Guide
HowTos / Create an SSH Session from Excel
In This Topic
Create an SSH Session from Excel
In This Topic

You can use macros to configure SSH connections for new sessions.

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 create-an-ssh-session.xlsm file. The download package contains everything you need to run the macros in this file. See Download the VBA Sample Sessions.

 

This Microsoft Excel macro creates, configures, and connects to a new SSH terminal connection.

This sample applies only to Open Systems terminals.

To run this sample

  1. In Microsoft Excel, open a new worksheet and then open the VBA editor.
  2. In the VBA Editor for an Excel worksheet, select the project and then from the Tools menu, add references to these Micro Focus libraries:
  1. Enter the following sample code in a Sheet object module.
    Create an SSH Session
    Copy Code
    Sub OpenSSHConnection()  
         Dim App As Attachmate_Reflection_Objects_Framework.ApplicationObject
         Dim Terminal As Attachmate_Reflection_Objects_Emulation_OpenSystems.Terminal
         Dim Frame As Attachmate_Reflection_Objects.Frame
     
         On Error Resume Next
         'Try to use the existing workspace
         Set App = GetObject("Reflection Workspace")
         On Error GoTo 0
         'Otherwise, Create New instance of Reflection
         If IsEmpty(App) Or (App Is Nothing) Then Set App = _
           CreateObject("Attachmate_Reflection_Objects_Framework.ApplicationObject")
         With App
             Do While .IsInitialized = False
                 .Wait 200
             Loop
             'Obtain the Frame Handle
             Set Frame = .GetObject("Frame")
             'Make it visible to the user
             Frame.Visible = True
         End With
     
         'Create an Open Systems control and immediately turn off autoconnect
         Set Terminal = App.CreateControl2("{BE835A80-CAB2-40d2-AFC0-6848E486BF58}")
         With Terminal
             .AutoConnect = False
      
            'Set the connection type
             .ConnectionType = ConnectionTypeOption_SecureShell
            'Set your hostname and other connection settings
             With .ConnectionSettingsSecureShell
                 .HostAddress = "hostName or IP Address"
                 .UserName = "admin"
             End With
         End With
     
         'Create a view for the terminal
         Set View = Frame.CreateView(Terminal)
        
         'Manually call connect because Auto is now disabled
         Terminal.Connect
      
     End Sub
    

  1. Set the values of the HostAddress and UserName properties and then press F5 to run the macro.

Concepts

To set up scripts that automatically connect to sessions with SSH, see the following technical notes.

Automating SSH, SFTP, and SCP with Windows Scheduled Tasks (http://support.attachmate.com/techdocs/2329.html)
Configuring Reflection for Public Key Authentication in Secure Shell Connections (http://support.attachmate.com/techdocs/1881.html)

 

See Also