Contact US

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!

*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

Tell VBA which Session to activete

Tell VBA which Session to activete

Tell VBA which Session to activete


I am currently using an excel VBA to activate an open session and sendkeys.

The problem I have is that the code opens the last session that was open and not the session i want.

(Here is the Code)  ....

Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System")
If (System Is Nothing) Then
MsgBox "error1"
End If
Set Sessions = System.Sessions

If (Sessions Is Nothing) Then
MsgBox "error2"
End If

Dim Sess0 As Object
SessName0$ = "Dice.EDP"

Set Sess0 = System.activesession
If (Sess0 Is Nothing) Then
MsgBox "error3"
End If

If Not Sess0.Visible Then Sess0.Visible = True

Sess0.Screen.SendKeys ("Hello")


The session I want to use is called "Dis" however the last session opened on the system is "MAINFRAME" and I want to sendkeys to "Dis"

Is there anyway I can tell VB to deal with "Dis" and NOT "MAINFRAME" as the ' System.activesession ' part of the code takes you to the "MAINFRAME" session as this was the last opened session.

Any help greatly appreciated.


RE: Tell VBA which Session to activete

Your problem is coming in the line:
Set Sess0 = System.activesession

the activesession is the last opened (I think).

You'll need to use the session object to find the session you want. I'm assuming that the session "Dis" is already open.

Set Sess0 = System.Sessions.Item("Dis.edp")

The sessions object has some interesting properties like count and item that will tell you how many sessions are open and what there names are. Since you're working in VBA, you can add a reference to your project that will help you a lot. From the VBA editor, choose tools>references then select Attachmate Extra!. Now you can DIM your objects as ExtraApplication, ExtraSessions and ExtraSession. This will give you all the available properties and methods to these objects.


RE: Tell VBA which Session to activete

Calculus, thanks for the reply, however I'm still having problems with this.

I replaced the line of code with your suggestion, however when I run the macro, I get the following error:

Run-time error '2147418113 (8000ffff)':

The specified session is not available

The sesssion is open on the system, however excel does not seem to understand this.

Any other suggestions ???

Many Thanks,

RE: Tell VBA which Session to activete

Yes, the best thing to do at this point is to see what sessions are available. I think your "Dis" is probably know as something else by the system. I suggest you loop through the sessions to see what they are named.


For Sess = 1 to Sessions.Count
rc% = Msgbox (Sessions.Item(Sess).Name & "   Index = " & Sess)
If StrComp(Sessions.Item(Sess).Name, "Extra", vbTextCompare) = 0 Then Exit For
Next Sess

Set Sess0 = System.Sessions.Item(Sess)

This will Show you the names of each session. You may also wannt to use the index of each session. I think I had to use the index number of the session when I did this. Remove the msgbox line when you get it working.


RE: Tell VBA which Session to activete


I have been doing battle with the ActiveSession issue for some time now (see Thread99-477787) and it would appear you have already been pointed in the best direction by calculus, However, I have also encountered the same Runtime error you refer to when using the System.Sessions.Item object.

I have 60 users running Win2K on desktop PC's that can use both Attachmate and Excel VBA macros referencing the .Item object without any problems, but I am unable to run the same macros on 3 laptops used by the managers without obtaining the Runtime error.... Fundamentally the laptops 'appear' to have the same overall build as the desktop PC's (Win2K Etc..) - unfortunately they are provided by the company via different channels and as such I am not permitted to alter/re-build to confirm this.

I have provided clean installs of both Extra! 6.5 & 6.7 on all laptops in an attempt to identify the problem, alas I can not find out why a particular 'build' would not allow the .Item object to be used without obtaining the Runtime error.

Regretably this has not provided a solution for you, but I felt that sharing my findings may possibly assist ?


RE: Tell VBA which Session to activete

I got a macro to work running two different sessions using these lines of code:

Set Sess0 = System.Sessions.Item("C:\Program Files\E!PC\Sessions\Session2.edp")

Sess0.screen. 'do something'

Set Sess0 = System.Sessions.Item("C:\Program Files\E!PC\Sessions\Session3.edp")

Sess0.screen. 'do something'

It seems you have to enter the file path for Extra/Excel to recognize which session you are trying to access.

Hope this helps.


RE: Tell VBA which Session to activete

This thread is fairly old, but I'll post my solution in the event that another user is reading this for a fix.

While the following may seem simplistic, I have found it to work well for my needs.

Rather than find the exact session name, I simply have VBA cycle through all active sessions and use GetString until it finds the first open session instance with the unique Screen name needed by the VBA script in order to continue  execution (although a string test against any text unique to the active page will work).

Obviously, certain details will have to be augmented for your environment:

    ' Evaluate open sessions to find COP877DS page
    ' -----------------------------------------
    Dim SessionCount As Integer
    Dim iCount As Integer    

    ' Set initial session test variables
    SessionCount = Sessions.Count
    'Reset counter variable
    iCount = 1
    ' Run test loop
    While iCount <= SessionCount
        'Gather ASI header value
        Header = Sess0.Screen.GetString(2, 73, 8)
        'MsgBox Sess0.Name & Chr(10) & header
        'If header does not equal OP/RR header, cycle through all
        'If not found, set SessionVerified to false
        If Header <> "COP877DS" Then
            Set Sess0 = System.ActiveSession
            If iCount = SessionCount Then
                MsgBox "The OP/RR query screen must be open for the macro to execute. Please navigate to OP/RR and try again."
                SessionVerified = False
            End If
            iCount = iCount + 1
            iCount = SessionCount + 1
            SessionVerified = True
        End If


    'End Code

I hope this helps someone.


RE: Tell VBA which Session to activete

I have not been able to actually solve this problem, but I have learned that ActiveSession seems to be the last session to run a macro. I tried opening and closing sessions and various other experiments, but ActiveSession always seems to default to the last macro session, sometimes even when running the macro from inside the session (menu bar, toolbar, keyboard).

oddly, this problem was nonexistent in old versions of Extra! because that version of Basic relied on the short name for the session - A, B, C, etc. instead of the session ID. this allowed you to specify the session and use the same macro on different machines without much coding. Personal Client doesn't seem to recognize the short name at all.

wish there was some obvious and easy fix for this. I'm disappointed at Attachmate's lack of support.

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