I have written numerous macros to get data from Attachmate to Excel which work great.
What I am struggling with is that after Attachmate is opened a simple logon script wont work unless Enter is pressed manually from the keyboard a number of times.
The username string is sent to Attachmate ok, then the first Sess0.Screen.SendKeys ("<Enter>") works ok, the password string is then sent to Attachmate ok but then the 2nd Sess0.Screen.SendKeys ("<Enter>") simply doesnt work.
I have tried a Sess0.Screen.WaitHostQuiet (1000)before sending the Enter but it still doesnt work.
If the user has logged in and out manually and then runs the macro it works fine, if the user manually presses enter a number of times when Attachmate is first opened it works fine.
If I step through the code the Enter command appears to execute but nothing happens in Attachmate.
Has anyone else come across this ?
What I am struggling with is that after Attachmate is opened a simple logon script wont work unless Enter is pressed manually from the keyboard a number of times.
The username string is sent to Attachmate ok, then the first Sess0.Screen.SendKeys ("<Enter>") works ok, the password string is then sent to Attachmate ok but then the 2nd Sess0.Screen.SendKeys ("<Enter>") simply doesnt work.
I have tried a Sess0.Screen.WaitHostQuiet (1000)before sending the Enter but it still doesnt work.
If the user has logged in and out manually and then runs the macro it works fine, if the user manually presses enter a number of times when Attachmate is first opened it works fine.
If I step through the code the Enter command appears to execute but nothing happens in Attachmate.
Has anyone else come across this ?
Code:
Sub Logon()
Dim sendCommand As String
Dim Sessions, System As Object, Sess0 As Object
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession
Dim enter As String
With Worksheets("Passwords")
sendCommand = .Cells(1, 2).Value
If sendCommand = "" Then
MsgBox "USER ID field (B1) in Passwords sheet is blank"
End If
Sess0.Screen.PutString sendCommand
Sess0.Screen.WaitHostQuiet (1000)
Sess0.Screen.SendKeys ("<Enter>")
Sess0.Screen.WaitHostQuiet (1000)
Do
DoEvents
Loop Until Sess0.Screen.Col = 11
sendCommand = .Cells(2, 2).Value
If sendCommand = "" Then
MsgBox "Password field (B2) in Passwords sheet is blank"
End If
Do
DoEvents
Loop Until Sess0.Screen.Col = 11
Sess0.Screen.PutString sendCommand
Sess0.Screen.WaitHostQuiet (1000)
Sess0.Screen.SendKeys ("<Enter>")
Do
DoEvents
Loop Until Sess0.Screen.Col = 54
Sess0.Screen.SendKeys ("yes")
Sess0.Screen.SendKeys ("<Enter>")
End With
End Sub