×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Excel VBA: Open Attachmate Session if not already open

Excel VBA: Open Attachmate Session if not already open

Excel VBA: Open Attachmate Session if not already open

(OP)
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

RE: Excel VBA: Open Attachmate Session if not already open



hi,

CODE

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

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Excel VBA: Open Attachmate Session if not already open

(OP)
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!

RE: Excel VBA: Open Attachmate Session if not already open

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

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 

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

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close