on 09-23-2015 9:57 AM
Hi everyone,
I'm a beginner in terms of SAP macro, and I'm stuck with one, I would like to copy a selection from SAP to Excel, would you be able to help me finding the missing part of the code?
Sub MasterC()
Set SapGuiAuto = GetObject("SAPGUI")
Set SapApp = SapGuiAuto.GetScriptingEngine
Set SapConnection = SapApp.Children(0)
Set SAPsession = SapConnection.Children(0)
SAPsession.findById("wnd[0]").maximize
SAPsession.findById("wnd[0]/tbar[0]/okcd").Text = "/nvdh2n"
SAPsession.findById("wnd[0]").sendVKey 0
SAPsession.findById("wnd[0]/usr/ctxtS_HITYP").Text = "a"
SAPsession.findById("wnd[0]/usr/ctxtS_DATE").Text = "22.09.2015"
SAPsession.findById("wnd[0]/usr/ctxtS_KUNNR-LOW").Text = "10032632"
SAPsession.findById("wnd[0]/usr/ctxtS_KUNNR-LOW").SetFocus
SAPsession.findById("wnd[0]/usr/ctxtS_KUNNR-LOW").caretPosition = 8
SAPsession.findById("wnd[0]").sendVKey 8
SAPsession.findById("wnd[0]/shellcont/shell").selectItem " 1", "Column1"
'I would like to paste the item above (simple name) into an Excel cell
End Sub
Thanks a lot guys
Hello Florian,
welcome to Scripting Language forum.
You can try this to read the first column of the first entry of a TableTreeControl:
Sub MasterC()
Set SapGuiAuto = GetObject("SAPGUI")
Set SapApp = SapGuiAuto.GetScriptingEngine
Set SapConnection = SapApp.Children(0)
Set SAPSession = SapConnection.Children(0)
SAPSession.findById("wnd[0]").maximize
SAPSession.findById("wnd[0]/tbar[0]/okcd").Text = "/nvdh2n"
SAPSession.findById("wnd[0]").sendVKey 0
SAPSession.findById("wnd[0]/usr/ctxtS_HITYP").Text = "a"
SAPSession.findById("wnd[0]/usr/ctxtS_DATE").Text = "22.09.2015"
SAPSession.findById("wnd[0]/usr/ctxtS_KUNNR-LOW").Text = "10032632"
SAPSession.findById("wnd[0]/usr/ctxtS_KUNNR-LOW").SetFocus
SAPSession.findById("wnd[0]/usr/ctxtS_KUNNR-LOW").caretPosition = 8
SAPSession.findById("wnd[0]").sendVKey 8
Set Tree = SAPSession.findById("wnd[0]/shellcont/shell")
topNode = CStr(Tree.topNode)
Key = topNode
nodeName = Tree.GetNodeTextByKey(Key)
colName = Tree.GetColumnNames.Item("0")
Set col = Tree.GetColumnCol(colName)
Sheet1.Cells(1, 1) = col.Item(0)
End Sub
You can find an excellent discussion and solution how to read columns of a TableTreeControl here.
Let us know your results.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.