【问题标题】:taking the value of the cell from SAP report从 SAP 报告中获取单元格的值
【发布时间】:2021-06-06 10:02:07
【问题描述】:

我在 SAP 中有报告,我需要从单元格中获取值(订单号)。

我怎样才能得到这个?

我想使用类似的东西 session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellRow = 12

但这仅指行号 (12)。

如何获取单元格的值,例如第 12 行第 9 列?

谢谢

【问题讨论】:

  • 我猜你的“报告”实现了一个GuiGridView 对象。我看不到获取单元格的值和设置属性currentCellRow 之间的关系。设置列不会帮助您获得一个单元格的值。你能澄清你的问题吗? (注意:currentCellColumn 包含列 name,SAP GUI 脚本中不使用列号)
  • 我的意思是——我需要将发票保存在订单名下。订单号在报告中列出(作为列表的以下位置,而不是作为标题)。
  • 请查看以下链接中的类似问题:answers.sap.com/questions/698148/sap-grid-copy-to-excel.html
  • 我如何从 SAP 报告中复制整行?
  • 我有这样的东西

标签: vba sap-gui


【解决方案1】:

我发现直接引用您想要从中获取信息的单元格更容易。

MyGrid = "wnd[0]/usr/cntlGRID1/shellcont/shell"
iRows = session.findById(MyGrid).RowCount()

Do While i < iRows ' i default value of 0
 session.findById(MyGrid).firstVisibleRow = i 'This is an auto scroll to keep info loading with more then 100 rows
 SAP_Info = session.findByID(MyGrid).getcellValue(i,"REFBN") 'SAP_Info as a variable to store the data rather than using copy/paste 
 
 i=i+1
 Cells(i, 1).Value = SAP_Info 'set to excel active work sheet cells in column A
Loop 

如果您想提取整行,我建议您使用数组并设置为表格。这是我获取人力确认信息的报告。

Sub Con_Report()
Dim ArrCells() As Variant

    Set SapGuiAuto = GetObject("SAPGUI")
    Set SAPApp = SapGuiAuto.GetScriptingEngine
    Set SAPCon = SAPApp.Children(0)
    Set session = SAPCon.Children(0)
MyGrid = "wnd[0]/usr/cntlGRID1/shellcont/shell"
hRows = session.findById(MyGrid).RowCount()

ReDim ArrCells(1 To hRows, 1 To 9)
session.findById(MyGrid).firstVisibleRow = 0
Do While h < hRows  'Fill excel sheet
    session.findById(MyGrid).firstVisibleRow = h
    ArrCells(h + 1, 1) = session.findById(MyGrid).getcellValue(h, "INGPR")
    ArrCells(h + 1, 2) = session.findById(MyGrid).getcellValue(h, "AUART")
    ArrCells(h + 1, 3) = session.findById(MyGrid).getcellValue(h, "AUFNR")
    ArrCells(h + 1, 4) = session.findById(MyGrid).getcellValue(h, "ZORDDESC")
    ArrCells(h + 1, 5) = session.findById(MyGrid).getcellValue(h, "TPLNR")
    ArrCells(h + 1, 6) = session.findById(MyGrid).getcellValue(h, "IARBPL")
    ArrCells(h + 1, 7) = session.findById(MyGrid).getcellValue(h, "NAME")
    ArrCells(h + 1, 8) = session.findById(MyGrid).getcellValue(h, "ISDD")
    ArrCells(h + 1, 9) = session.findById(MyGrid).getcellValue(h, "ISMNW")
    
    
    h = h + 1
Loop
Range("B3").Resize(UBound(ArrCells, 1), UBound(ArrCells, 2)).Value = ArrCells
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-30
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多