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


Controlling a mainframe with VBA

Controlling a mainframe with VBA

Controlling a mainframe with VBA

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:"


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")

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


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


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

You can try to set Wait optional argument to True in Sendkeys.
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).


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