Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA: Open Attachmate Session if not already open 1

Status
Not open for further replies.

SuperKoopa

Technical User
Jul 30, 2012
26
US
Hello,

I have yet another question for a different situation. I would like to create a button in excel that opens an an Attachmate Session and then sendkeys, however, if a session is already open I would like it just to bring that existing Attachmate session forward as the active window. Right now I am using the code below to open a session and perform the sendkeys, but I have no idea how to add coding for an existing attachmate to be recognized. So as you can imagine if the button I've created using the code below is clicked and there is an existing attachmate open, it screws it up. Any assistance I would absolutely appreciate! Thank you!
---------------------------------------------------------------------------------


Sub OpenLSP()

Set System = CreateObject("EXTRA.System") ' Gets the system object

If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If

Set session = System.Sessions.Open("C:\Program Files\Attachmate\EXTRA!\Sessions\Morgan.EDP")

If (session Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping macro playback."
Stop
End If

g_HostSettleTime = 300 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

If Not session.Visible Then session.Visible = True
session.Screen.waithostquiet (g_HostSettleTime)

Dim Sess0 As Object
Set Sess0 = System.ActiveSession
session.Screen.waithostquiet (g_HostSettleTime)

Do
session.Screen.waithostquiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("X LSP<Enter>")
session.Screen.waithostquiet (g_HostSettleTime)
Loop Until Sess0.Screen.GetString(1, 29, 6) = "Signon"
session.Screen.waithostquiet (g_HostSettleTime)

End Sub
 


hi,
Code:
If System.Sessions.Count = 0 then
  'open a new session
else
  'assign existing session
  Set session = System.Sessions(1)
end if


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks for the quick reply, and I hate to trouble you futher, but how would I plug that into what I already have? I appreciate your guidance, you're pretty much a genius!
 
Code:
Sub OpenLSP()

Set System = CreateObject("EXTRA.System") ' Gets the system object

If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
[b]
If System.Sessions.Count = 0 then
  'open a new session
  Set session = System.Sessions.Open("C:\Program Files\Attachmate\EXTRA!\Sessions\Morgan.EDP")
else
  'assign existing session
  Set session = System.Sessions(1)
end if 
[/b]
If (session Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping macro playback."
Stop
End If

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top