这是我的第一篇论坛帖子。我一直在寻找无处不在的信息,而我找不到我正在搜索的信息。如果我说错了,请原谅我。
我创建了一个Excel电子表格,用于从SAP中的查询中提取实时数据,并将该信息粘贴回Excel Extraction Pic。从那里开始,我打开交易ME38以根据提取的数据更新计划行。我需要去"预定.."专栏(我知道" txtEKET-MENGE")并将显示的数字更改为" Qty Delivered" (这是提取的一部分);但是,我只需要在" Schedule ..."中的某些单元格上执行此操作。列(" txtEKET-ETENR")[提取时列出的数据]。 SAP Table Pic
这是我到目前为止所做的。
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
以下是Function 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
当它到达&#34;设置网格...&#34;它结束了这个功能而没有做任何事情。
非常感谢任何见解。
答案 0 :(得分: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