Sub ToggleConnection()
'Give the Ibm terminal a name. This will provide ability to retrieve
'the session with Application.GetControlsByName.
'This could be done for each session, perhaps on AfterConnect event.
ThisIbmTerminal.Name = "IBMSession1"
'The following demonstrates getting a set of sessions/controls with a given name
Dim controls() As Variant 'An array of type Variant/Object/Terminal
'Return all controls named "IBMSession1"
controls = Application.GetControlsByName("IBMSession1")
If UBound(controls) = -1 Then
Exit Sub
Else
'Toggle the connection state for all controls in array
For i = 0 To UBound(controls)
If controls(i).IsConnected Then
controls(i).Disconnect
Else
controls(i).Connect
End If
Next i
End If
End Sub