1

我创建了一个 Excel 电子表格,它从 SAP GUI 中的查询中提取实时数据并将该信息粘贴回 Excel 中 提取图片

从那里,我打开事务 ME38 以根据提取的数据更新计划行。我需要转到“scheduled..”列(我知道它是“txtEKET-MENGE”)并将显示的数字更改为“Qty Delivered”(这是提取的一部分);但是,我只需要对“Schedule...”列(“txtEKET-ETENR”)中的某些单元格执行此操作[也列出了提取数据]。
SAP 表图片

当它到达“设置网格...”时,它会结束该功能并且不执行任何其他操作。

任何见解将不胜感激。

这是我到目前为止所做的。

Set xclapp = CreateObject("Excel.Application")
Set xclwbk = ThisWorkbook
Set xclsht = xclwbk.Sheets("Sheet1")
For k = 2 To ActiveCell.SpecialCells(11).Row
For j = 1 To ActiveCell.SpecialCells(11).Column
If j = 14 Then Purch = xclsht.Cells(k, j).Value
If j = 15 Then Item = xclsht.Cells(k, j).Value
If j = 16 Then SLine = xclsht.Cells(k, j).Value
If j = 8 Then PGI = xclsht.Cells(k, j).Value
Next
myTransaction = "ME38"

Session.FindById("wnd[0]/tbar[0]/okcd").Text = "/n" & myTransaction

Session.FindById("wnd[0]").sendVKey 0

On Error Resume Next
Session.FindById("wnd[0]/usr/ctxtRM06E-EVRTN").Text = Purch
Session.FindById("wnd[0]/usr/ctxtRM06E-EVRTN").caretPosition = 10
Session.FindById("wnd[0]").sendVKey 0
Session.FindById("wnd[0]/usr/txtRM06E-EBELP").Text = Item
Session.FindById("wnd[0]/usr/txtRM06E-EBELP").caretPosition = 3
Session.FindById("wnd[0]").sendVKey 0
Session.FindById("wnd[0]/tbar[1]/btn[30]").press
Session.FindById("wnd[0]/tbar[1]/btn[2]").press
Call SelectRowOnGrid
Session.FindById("wnd[0]/mbar/menu[0]/menu[0]").Select
Session.FindById("wnd[0]").Close
  On Error Resume Next

  Session.FindById("wnd[1]/usr/btnSPOP-OPTION1").press
Next
End If
If Err.Number <> 0 Then

'The Excel worksheet has e.g. 3 columns of data and an error column.

xclsht.Cells(j, 21).Value = "Here is an error."

Else

xclsht.Cells(j, 21).Value = "O.K."

End If

On Error GoTo 0

下面是函数 SelectRowOnGrid。

Function SelectRowOnGrid()
Dim grid As SAPFEWSELib.GuiTableControl
Dim columnname As SAPFEWSELib.GuiTableColumn
Dim texttofind As String
Set grid = Session.FindById("wnd[0]/usr/tblSAPMM06ETC_1117/")
Set columnname = Session.FindById("wnd[0]/usr/tblSAPMM06ETC_1117/txtEKET-  ETENR")
texttofind = xclsht.Cells(k, 16).Value

    For k = 0 To grid.RowCount - 1

If grid.GetCellValue(k, columnname) = texttofind Then
grid.SetCurrentCell
grid.DoubleClickCurrentCell
End If

    Next k

End Function
4

1 回答 1

0

我会给你一个例子,说明如何在 SAP 中处理一个表。在您的情况下,您使用 GRID 的命令,这是不正确的。

例如:

myFile = "z:\tmp\test.xlsx"
mySheet = "Test"

Set xclApp = CreateObject("Excel.Application")
Set xclwbk = xclapp.Workbooks.Open(myFile)
set xclsht = xclwbk.Sheets(mySheet)

xclApp.Visible = True
xclapp.DisplayAlerts = false

k = 1

do

set myTable = session.findById("wnd[0]/usr/ssubITEMS:SAPLFSKB:0100/tblSAPLFSKBTABLE")

 if k = 1 then
 'rows = myTable.RowCount
  cols = myTable.Columns.Count
  vRows = myTable.VisibleRowCount
  for j = 0 to cols - 1
   xclsht.Cells(k,j + 1).Value = myTable.columns.elementAt(j).title
  next
  k = k + 1
 end if

for i = 0 to vRows - 1
l = 1
 for j = 0 to Cols - 1
  on error resume next
  myVariable = trim(myTable.GetCell(i,j).Text) 
  if err.number <> 0 then  exit for      
  on error goto 0
  if left(right(myVariable,3),1) = "," then 
   myVariable = replace(myVariable, "." , "")
   myVariable = replace(myVariable, "," , "")
   xclsht.Cells(k,l).Value = myVariable/100
  else 
   xclsht.Cells(k,l).Value = myVariable 
  end if
  l = l + 1
 next
 if err.number <> 0 then  exit for       
 k = k + 1
next
if err.number <> 0 then  exit do       
myTable.VerticalScrollbar.Position = myTable.VerticalScrollbar.Position + vRows

Loop 
xclapp.ActiveWorkbook.Save

Set xclwbk = Nothing
Set xclsheet = Nothing
set xclapp = Nothing

问候, ScriptMan

于 2017-08-24T12:11:46.540 回答