how to do ctrl+c from mainframe window

chaitu566
NewLounger
Posts: 4
Joined: 16 Jun 2012, 05:18

how to do ctrl+c from mainframe window

Post by chaitu566 »

hi,

i'm trying to pass some data to mainfame and do some operations and trying to take a screen shot to word document. in this way i was able to pass data to manfrme nd do operations but not taking screen shot to word document. below is my code which i'm using for it. please advice me for taking screen shot..

Code: Select all

Sub Pm()
rw = 2
r2 = 2
'Connects to PCOMM and checks for lockouts.
Dim autECLSession As Object
Dim autECLConnList As Object
Dim wshshell As Object
Dim oScrShell As Object

Dim a As Integer


 Set wshshell = CreateObject("WScript.Shell")
 
 'Set autECLSession = CreateObject("word.Application")
   Set autECLSession = CreateObject("PCOMM.autECLSession")
'give the mainframe session in which macro has to be executed --> here it is Session B
autECLSession.SetConnectionByName ("A")
Set autECLConnList = CreateObject("PCOMM.autECLConnList")
'If ThisWorkbook.PCOMM_Connect(autECLSession, autECLConnList) = False Then slush = MsgBox("You appear to be logged out of Mainframe. Please" & (Chr(13)) & "log back in and try again.", 16, "Mainframe locked"): Exit Sub
'  select the worksheet --> Sheet1
Set objSheet0 = ActiveWorkbook.Worksheets(1)
autECLSession.autECLPS.SendKeys "[home]"
autECLSession.autECLPS.SendKeys "[erase eof]"
' wshshell.Run "winword"

If objSheet0.Cells(rw, 1).Value <> "" Then
   a = 1
 
Do While objSheet0.Cells(r2, 1).Value <> ""
    autECLSession.autECLPS.SendKeys "[home]"
    autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 1).Value & "[enter]"
    autECLSession.autECLPS.SendKeys "[home]"
    autECLSession.autECLPS.SendKeys "[tab]" & "[erase eof]" & "[tab]"
    autECLSession.autECLPS.SendKeys "[erase eof]" & "[tab]" & "[erase eof]"
    autECLSession.autECLPS.SendKeys "[tab]" & "[erase eof]"
    autECLSession.autECLPS.SendKeys "[home]"
    autECLSession.autECLPS.SendKeys "[tab]" & "[tab]" & "[tab]"
    autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 2).Value
    autECLSession.autECLPS.SendKeys "[ENTER]"
    autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 3).Value
    autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 4).Value
    autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 5).Value
  '  autECLSession.autECLPS.SendKeys "[tab]"
    autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 6).Value
 '   autECLSession.autECLPS.SendKeys "[tab]"
    autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 7).Value
'    autECLSession.autECLPS.SendKeys "[tab]"
    autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 8).Value
    autECLSession.autECLPS.SendKeys "[ENTER]"
    autECLSession.autECLPS.SendKeys "[PF10]"
   ' autECLSession.autECLPS.SendKeys "{^C}"
' autECLSession.autECLPS.SendKeys "^{C}"
    wshshell.AppActivate "Session A - [43 x 80]"
'    autECLSession.autECLPS.GetText [(1, 80, 43)]
    
  autECLSession.autECLPS.SendKeys "^c"
     If a = 1 Then
          
       wshshell.Run "winword"
       wshshell.AppActivate "Document1 - Microsoft Word"
      
'       wshshell.SendKeys ["%a"]
 '
        
   '    wshshell.SendKeys ("i")
  '     wshshell.SendKeys ("t")

      
    '   wshshell.SendKeys ("1")


'       wshshell.SendKeys "[%tab]"
   '    wshshell.SendKeys ("1")
            
     
       a = a + 100
       
       End If
        '      oScrShell.SendKeys "^V"
      wshshell.SendKeys "^v"
           wshshell.SendKeys "[tab]"
 r2 = r2 + 1
        Loop
      wshshell.SendKeys "[tab]"
      
        a = 1
         rw = rw + 1
         
   End If

End Sub


help will be :clapping:

thanks in advance..
chaitanya

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to do ctrl+c from mainframe window

Post by HansV »

Welcome to Eileen's Lounge!

To take a screenshot, you need some Windows API code. Copy the following code to the top of your module, before all Subs and Functions:

Code: Select all

Private Declare Sub keybd_event Lib "user32" _
   (ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, _
    ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12
Also copy the following macro into the module:

Code: Select all

Sub AltPrintScreen()
    keybd_event VK_MENU, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
    keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End Sub
The AltPrintScreen macro takes a screenshot of the active window, just like pressing Alt+PrintScreen.

Here is how you might be able to use it in your code. I can't test it since I don't use PCOMM.

Code: Select all

Sub Pm()
    Dim rw As Long
    Dim r2 As Long
    Dim autECLSession As Object
    Dim autECLConnList As Object
    Dim wshshell As Object
    Dim a As Long
    Dim objSheet0 As Worksheet

    Set wshshell = CreateObject("WScript.Shell")

    'Connects to PCOMM and checks for lockouts.
    Set autECLSession = CreateObject("PCOMM.autECLSession")
    'give the mainframe session in which macro has to be executed -->
    'here it is Session B (?)
    autECLSession.SetConnectionByName "A"
    Set autECLConnList = CreateObject("PCOMM.autECLConnList")
    autECLSession.autECLPS.SendKeys "[home]"
    autECLSession.autECLPS.SendKeys "[erase eof]"

    '  select the worksheet --> Sheet1
    Set objSheet0 = ActiveWorkbook.Worksheets(1)
    rw = 2
    r2 = 2
    If objSheet0.Cells(rw, 1).Value <> "" Then
        a = 1
        Do While objSheet0.Cells(r2, 1).Value <> ""
            autECLSession.autECLPS.SendKeys "[home]"
            autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 1).Value & "[enter]"
            autECLSession.autECLPS.SendKeys "[home]"
            autECLSession.autECLPS.SendKeys "[tab]" & "[erase eof]" & "[tab]"
            autECLSession.autECLPS.SendKeys "[erase eof]" & "[tab]" & "[erase eof]"
            autECLSession.autECLPS.SendKeys "[tab]" & "[erase eof]"
            autECLSession.autECLPS.SendKeys "[home]"
            autECLSession.autECLPS.SendKeys "[tab]" & "[tab]" & "[tab]"
            autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 2).Value
            autECLSession.autECLPS.SendKeys "[ENTER]"
            autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 3).Value
            autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 4).Value
            autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 5).Value
            autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 6).Value
            autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 7).Value
            autECLSession.autECLPS.SendKeys objSheet0.Cells(r2, 8).Value
            autECLSession.autECLPS.SendKeys "[ENTER]"
            autECLSession.autECLPS.SendKeys "[PF10]"
            wshshell.AppActivate "Session A - [43 x 80]"
            autECLSession.autECLPS.SendKeys "^c"
            If a = 1 Then
                wshshell.Run "winword"
                wshshell.AppActivate "Document1 - Microsoft Word"
                a = a + 100
            End If
            wshshell.SendKeys "^v"
            wshshell.SendKeys "[tab]"
            ' ****** New Code ******
            ' Activate mainframe session
            wshshell.AppActivate "Session A - [43 x 80]"
            ' Take screenshot
            AltPrintScreen
            ' Activate Word
            wshshell.AppActivate "Document1 - Microsoft Word"
            ' Paste
            wshshell.SendKeys "^v"
            wshshell.SendKeys "[tab]"
            ' ****** End of New Code ******
            r2 = r2 + 1
        Loop
        wshshell.SendKeys "[tab]"
        a = 1
        rw = rw + 1
    End If
End Sub
Best wishes,
Hans

chaitu566
NewLounger
Posts: 4
Joined: 16 Jun 2012, 05:18

Re: how to do ctrl+c from mainframe window

Post by chaitu566 »

Hi Hans,

:thankyou: Quick reply...!!

have tried code which you have given to me.. it worked.
but as per my project i should do copy(PCOMM will allow to do CTRL+C) and paste in a word document for documentation purpose. this will reduce lots of manual effort for me. could u please assist me using the CTRL+C in the VB code...



thanks,
Chaitanya.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to do ctrl+c from mainframe window

Post by HansV »

You already have code that copies the text in the PCOMM session:

autECLSession.autECLPS.SendKeys "^c"

Doesn't that work?
Best wishes,
Hans

chaitu566
NewLounger
Posts: 4
Joined: 16 Jun 2012, 05:18

Re: how to do ctrl+c from mainframe window

Post by chaitu566 »

no, it did not work..

thanks,
chaitanya

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to do ctrl+c from mainframe window

Post by HansV »

I found a reference stating that PComm uses Shift+Insert to copy, not Ctrl+C.
Moreover, as far as I know, special keys should be enclosed in curly brackets { }, not in square brackets [ ].
So try

autECLSession.autECLPS.SendKeys "+{INSERT}"
Best wishes,
Hans