I have a VBA code that scripts some SAP transactions then select a whole column from a grid on SAP GUI.
I am successful till here but I want to copy the column and paste it in an Excel sheet, but I can't do that.
I tried to open the context menu to choose copy text but it doesn't work. I tried to send CTRL+C stroke from keyboard but also failed. If someone can help me with that I will be very grateful.
Here is my code:
Sub lolo()
If Not IsObject(App) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set App = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = App.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject App, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/btn%_EQUNR_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[24]").press
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[0]/usr/txtSELCOUNT").Text = "1"
session.findById("wnd[0]/usr/txtSELCOUNT").SetFocus
session.findById("wnd[0]/usr/txtSELCOUNT").caretPosition = 14
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell -1, "PTTXT"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "PTTXT"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&FILTER"
session.findById("wnd[1]").sendVKey 4
session.findById("wnd[2]/usr/lbl[1,23]").SetFocus
session.findById("wnd[2]/usr/lbl[1,23]").caretPosition = 2
session.findById("wnd[2]").sendVKey 2
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell -1, "CNTRC"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "CNTRC"
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys "^C"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu
End Sub