Hi all,
Quick question. I have an application link which checks to make sure a program is open, and if not, opens a new session. If the session is already open, Excel retains focus. If the session is not open, the application gains focus when opened, and I need to find the command to give focus back to Excel.
I've tried ActiveWorkbook.Activate (Activate being what I would use to call focus to the session object) but that didn't work, and a number of other tries have failed as well.
I definately do NOT want to use appActivate, as it's far too unreliable, requiring exact window naming which may change at any time.
The code I use to check for a session is below.
''' INITIALISE HOST '''
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping session."
Exit Sub
End If
Set Sessions = System.Sessions
If (Sessions Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping session."
Exit Sub
End If
'Choose a session not attached to CIS...
SessName1$ = "c:\Program Files\Attachmate\EXTRA!\Sessions\Host3.edp"
Set Sess1 = Sessions.Item(SessName1$)
... Main code goes here. Ideally the check to make sure Excel is the active window would go here as well.
...
...
Exit Sub
Err_Handle:
Select Case Err.Number
Case "-2147418113" 'Session not open
Ans = MsgBox(SessName1 + " is not currently open. Open it?", 1)
If Ans = vbOK Then
Ans = 0
SessFlag = True
Set Sess1 = Sessions.Open(SessName1)
ElseIf Ans = vbCancel Then
Exit Sub
Else
MsgBox ("Failed to open " + SessName1 + ". Stopping session.")
Exit Sub
End If
Resume Next
Thanks for your help!
-Bob
Bookmarks