title: vba code to copy a column from sap window and paste the values in excel sheet
body: <p>i have a code that do some SAP transactions on the sap then select a whole column from a grid on a sap i am successful till here but i want to copy the column and past it in an excel sheet but i cant 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:</p>
  
  <pre><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 "&amp;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
  </code></pre>