Controlling a mainframe with VBA
Controlling a mainframe with VBA
(OP)
Hi all,
I'm attempting to control a mainframe to automate a manual process using a sort of screen scraping method with the Application.SendKeys function. I've written code which does just that, but I've hit a wall. I've scoured the internet and found no solutions! The mainframe requires the enter key to be used, NOT the return key in order to move through the system. SendKeys to my knowledge does not allow me to differentiate to my knowledge.
Does anyone know what code might work or any work arounds? I've posted the code below. FYI - control+A, F10 and Page up all work with a keyboard, too, but not with SendKeys. Also, the online forums I read state that it's "Enter" or "~". The code below works fine until I get to the 'enter' (highlighted in yellow). I've highlighted commented text in orange.
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal Enable As Boolean) As Boolean
Private Sub RunOsk_on64Bit()
' This is a test macro to switch between TRUST and excel
Dim IDTRUST As Variant
Dim Path As String
Dim IDEXCEL As Worksheet
'........................................................................................................................
' Set the Path variable equal to the path of your program's installation
Path = "C:\Program Files (x86)\WinVVTN\WinVVTN\WinVVTN.exe"
IDTRUST = Shell("C:\Program Files (x86)\WinVVTN\WinVVTN.exe", vbNormalFocus)
Application.Wait Now + TimeValue("00:00:12")
MsgBox "Please log in to WinVV and leave it on the blank input screen. This is to enable a TRJG search."
Dim IDnotepad As Double ' to identify application with AppActivate
Workbooks("Automated Incident Number Correction in TRUST Macro 2.0.xlsm").Sheets("1").Activate
' IDnotepad = Shell("Notepad", vbMaximizedFocus)
'' MsgBox IDnotepad, vbOKOnly, "Notepad ID:"
Range("B2").Select
ActiveCell.Copy
AppActivate "SCR1 - WinVV Session 1", True
'''''''''''''''''Call OpenOSK
SendKeys "TRJG "
Application.Wait Now + TimeValue("00:00:01")
'''' SendKeys "R"
'''' Application.Wait Now + TimeValue("00:00:01")
'''' SendKeys "J"
'''' Application.Wait Now + TimeValue("00:00:01")
'''' SendKeys "G" {PGUP} {ENTER}
'''' Application.Wait Now + TimeValue("00:00:01")
'''' SendKeys " "
Application.Wait Now + TimeValue("00:00:01")
SendKeys "^(V)"
Application.Wait Now + TimeValue("00:00:01")
''''''''''''''''''''''''''''''''''' OSK = Shell("osk.exe")
Const SW_SHOWNORMAL = 1
On Error Resume Next
Wow64EnableWow64FsRedirection False
ShellExecute 0, "open", "osk.exe", "", "C:\windows\system32\osk.exe", SW_SHOWNORMAL
Wow64EnableWow64FsRedirection True
Application.SendKeys ("{ENTER}")
' SendKeys "{PGUP}"([F10])
' Application.SendKeys "%{F10}"
' Application.SendKeys "{CHAR(13)}"
' Application.SendKeys "%{F1}"
' Application.Wait Now + TimeValue("0:00:01")
I'm attempting to control a mainframe to automate a manual process using a sort of screen scraping method with the Application.SendKeys function. I've written code which does just that, but I've hit a wall. I've scoured the internet and found no solutions! The mainframe requires the enter key to be used, NOT the return key in order to move through the system. SendKeys to my knowledge does not allow me to differentiate to my knowledge.
Does anyone know what code might work or any work arounds? I've posted the code below. FYI - control+A, F10 and Page up all work with a keyboard, too, but not with SendKeys. Also, the online forums I read state that it's "Enter" or "~". The code below works fine until I get to the 'enter' (highlighted in yellow). I've highlighted commented text in orange.
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal Enable As Boolean) As Boolean
Private Sub RunOsk_on64Bit()
' This is a test macro to switch between TRUST and excel
Dim IDTRUST As Variant
Dim Path As String
Dim IDEXCEL As Worksheet
'........................................................................................................................
' Set the Path variable equal to the path of your program's installation
Path = "C:\Program Files (x86)\WinVVTN\WinVVTN\WinVVTN.exe"
IDTRUST = Shell("C:\Program Files (x86)\WinVVTN\WinVVTN.exe", vbNormalFocus)
Application.Wait Now + TimeValue("00:00:12")
MsgBox "Please log in to WinVV and leave it on the blank input screen. This is to enable a TRJG search."
Dim IDnotepad As Double ' to identify application with AppActivate
Workbooks("Automated Incident Number Correction in TRUST Macro 2.0.xlsm").Sheets("1").Activate
' IDnotepad = Shell("Notepad", vbMaximizedFocus)
'' MsgBox IDnotepad, vbOKOnly, "Notepad ID:"
Range("B2").Select
ActiveCell.Copy
AppActivate "SCR1 - WinVV Session 1", True
'''''''''''''''''Call OpenOSK
SendKeys "TRJG "
Application.Wait Now + TimeValue("00:00:01")
'''' SendKeys "R"
'''' Application.Wait Now + TimeValue("00:00:01")
'''' SendKeys "J"
'''' Application.Wait Now + TimeValue("00:00:01")
'''' SendKeys "G" {PGUP} {ENTER}
'''' Application.Wait Now + TimeValue("00:00:01")
'''' SendKeys " "
Application.Wait Now + TimeValue("00:00:01")
SendKeys "^(V)"
Application.Wait Now + TimeValue("00:00:01")
''''''''''''''''''''''''''''''''''' OSK = Shell("osk.exe")
Const SW_SHOWNORMAL = 1
On Error Resume Next
Wow64EnableWow64FsRedirection False
ShellExecute 0, "open", "osk.exe", "", "C:\windows\system32\osk.exe", SW_SHOWNORMAL
Wow64EnableWow64FsRedirection True
Application.SendKeys ("{ENTER}")
' SendKeys "{PGUP}"([F10])
' Application.SendKeys "%{F10}"
' Application.SendKeys "{CHAR(13)}"
' Application.SendKeys "%{F1}"
' Application.Wait Now + TimeValue("0:00:01")
RE: Controlling a mainframe with VBA
combo
RE: Controlling a mainframe with VBA
Thanks, but neither work. I've tried them from the same page you posted!
I think the problem might lie with the bespoke old software (at least 1980's era).
RE: Controlling a mainframe with VBA
RE: Controlling a mainframe with VBA
Thanks for your reply. Yes, but I just thought I'd check one last time as I'm getting a lot of pressure to make sure it definitely cannot be done. The thing that doesn't make sense to me is that it accepts the other SendKey commands, but not enter...
RE: Controlling a mainframe with VBA
SendKeys in VBA and excel Application may behave differently, try both (Sendkeys and Applicatoin.SendKeys).
I don't know how this will work in 64 bit environment, but you can try.
For testing try the code without On Error Resume Next, reset error trapping as soon as possible (On Error GoTo 0), clear possible error before (Err.Clear).
combo