Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling a mainframe with VBA

Status
Not open for further replies.

andy7172289

Technical User
Aug 16, 2016
19
GB
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()



[highlight #F57900]
' This is a test macro to switch between TRUST and excel[/highlight]


Dim IDTRUST As Variant
Dim Path As String
Dim IDEXCEL As Worksheet

[highlight #F57900]'........................................................................................................................[/highlight]


[highlight #F57900] ' Set the Path variable equal to the path of your program's installation[/highlight]
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


[highlight #F57900]' IDnotepad = Shell("Notepad", vbMaximizedFocus)
'' MsgBox IDnotepad, vbOKOnly, "Notepad ID:"[/highlight]

Range("B2").Select
ActiveCell.Copy

AppActivate "SCR1 - WinVV Session 1", True



'''''''''''''''''Call OpenOSK


SendKeys "TRJG "
Application.Wait Now + TimeValue("00:00:01")
[highlight #FCAF3E]'''' 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 " "[/highlight]
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


[highlight #FCE94F] Application.SendKeys ("{ENTER}")[/highlight]



[highlight #F57900]' SendKeys "{PGUP}"([F10])
' Application.SendKeys "%{F10}"
' Application.SendKeys "{CHAR(13)}"
' Application.SendKeys "%{F1}"
' Application.Wait Now + TimeValue("0:00:01")
[/highlight]
 
Combo,

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).
 
Didn't we agree back in January that winvvtn was flakey? Thread707-1783604
 
Strongm,

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

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top