如何使用 excel VBA 将值从 SAP 树视图复制到 Excel sheet

How to copy value from SAP Tree View to Excel sheet using excel VBA

我想从 SAP“MMBE”事务中复制 Excel sheet 中 material 的所选股票值:

如果有人可以帮助使用 excel VBA 语法复制附加快照中突出显示的值。

虽然您可以使用 SAP 记录器中的构建记录您的脚本并且只需单击适当的单元格两次以了解它有哪些索引,但很难预测列号和名称。 如果您的表彼此不同,它将变得越来越复杂。您需要首先获取您感兴趣的列名,然后将其与键等进行比较。 尝试使用 SAP gui 脚本帮助文件,它就在 "SAP scripting and playback" 菜单选项的正下方。

Public SapGuiAuto
Public SetApp
Public Connection
Public session
Public theCell As String 'may be of anything else you need if casted properly

Sub example()

    Dim nameConstructor As String
    nameConstructor = "          "

    Set SapGuiAuto = GetObject("SAPGUI")
    Set SetApp = SapGuiAuto.GetScriptingEngine
    Set Connection = SetApp.Children(0)
    Set session = Connection.Children(0)

    theCell = session.findById("wnd[0]/usr/cntlCC_CONTAINER/shellcont/shell/shellcont[1]/shell[1]").GetItemText(nameConstructor & "6", "C" & nameConstructor & "1")
    MsgBox theCell
    Cells(1, 1) = theCell

End Sub