当前,我有一个脚本可以从excel工作表中复制数据,并将其粘贴到事务代码级别的SAP中。
我的代码所做的是按每个ID(例如AA / AB)过滤日历选择,然后将“开始日期”和“结束日期”的数据复制到规模ID中。保存更改,然后移至下一个ID。
假设我有一个Excel工作表,其中有多个日历项相同。我该怎么做才能使excel检查下一行是否与当前行具有相同的日历ID,然后代替保存,复制并粘贴相同ID的开始/结束日期,然后才移至下一个日历。
tldr:比较当前列和下面的列;如果两列都相同,则继续进行更改;否则保存并返回。
代码如下:
Sub Main()
Dim row As Integer
Dim Session
'1. System name entry
sSystemName = sSystemName_EntrySTD()
'2. Connect to open SAP session
If bSessionConfirmSTD(Session, sSystemName) = False Then
MsgBox sSystemName & " session is not opened", vbCritical
End
End If
'3. Display status in EXCEL
application.StatusBar = "Attached to active session"
On Error Resume Next
'4. for all rows in active sheet (Tabelle1)
row = 2
While Tabelle1.Cells(row, 1).Value <> ""
Dim s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19 As String
Dim i As Integer
'5. Get value from first column of current row
s1 = Tabelle1.Cells(row, 1).Value
s2 = Tabelle1.Cells(row, 2).Value
s3 = Tabelle1.Cells(row, 3).Value
s4 = Tabelle1.Cells(row, 4).Value
s5 = Tabelle1.Cells(row, 5).Value
s6 = Tabelle1.Cells(row, 6).Value
s7 = Tabelle1.Cells(row, 7).Value
s8 = Tabelle1.Cells(row, 8).Value
s9 = Tabelle1.Cells(row, 9).Value
s10 = Tabelle1.Cells(row, 10).Value
s11 = Tabelle1.Cells(row, 11).Value
s12 = Tabelle1.Cells(row, 12).Value
s13 = Tabelle1.Cells(row, 13).Value
s14 = Tabelle1.Cells(row, 14).Value
s15 = Tabelle1.Cells(row, 15).Value
s16 = Tabelle1.Cells(row, 16).Value
s17 = Tabelle1.Cells(row, 17).Value
s18 = Tabelle1.Cells(row, 18).Value
s19 = Tabelle1.Cells(row, 19).Value
'6. Update status in EXCEL
application.StatusBar = "Processing row " & RTrim(LTrim(Str(row))) & ": " & s1
'BEGIN Paste your script here
'===============================================================================================================
Session.findById("wnd[0]").maximize
Session.findById("wnd[0]/tbar[0]/okcd").Text = "scal"
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]/usr/radFMEN-FABKAL").Select
Session.findById("wnd[0]/usr/radFMEN-FABKAL").SetFocus
Session.findById("wnd[0]/usr/btnUPDATE").press
Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellRow = -1
Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "IDENT"
Session.findById("wnd[0]/tbar[1]/btn[38]").press
Session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/ctxt%%DYN001-LOW").Text = s1
Session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/ctxt%%DYN001-LOW").caretPosition = 2
Session.findById("wnd[1]").sendVKey 0
Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = ""
Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectedRows = "0"
Session.findById("wnd[0]/tbar[1]/btn[7]").press
Session.findById("wnd[0]/tbar[1]/btn[17]").press
Session.findById("wnd[0]/tbar[1]/btn[13]").press
Session.findById("wnd[1]/usr/chkTIFAB-ARBTAG").Selected = s4
Session.findById("wnd[1]/usr/ctxtTIFAB-DATUMVON").Text = s2
Session.findById("wnd[1]/usr/ctxtTIFAB-DATUMBIS").Text = s3
Session.findById("wnd[1]/usr/txtTFAIT-LTEXT").Text = s5
Session.findById("wnd[1]/usr/txtTFAIT-LTEXT").SetFocus
Session.findById("wnd[1]/usr/txtTFAIT-LTEXT").caretPosition = 11
Session.findById("wnd[1]").sendVKey 0
'===============================================================================================================
'END Paste your script here
Tabelle1.Cells(row, 15).Value = Session.findById("wnd[0]/sbar").Text
'7. Log processed entries in Tabelle1
Tabelle1.Cells(row, 16).Value = "Done"
'8. Continue with next row
row = row + 1
Wend
application.StatusBar = "Processing finished"
On Error GoTo 0
Exit Sub
info:
MsgBox "error on line " & row
End Sub
答案 0 :(得分:0)
不知道我是否正确理解,应该实际比较什么。但是一种可能的解决方案可能看起来像这样:
. . .
'4. for all rows in active sheet (Tabelle1)
row = 2
While Tabelle1.Cells(row, 1).Value <> ""
Dim s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19 As String
Dim i As Integer
'5. Get value from first column of current row
s1 = Tabelle1.Cells(row, 1).Value
if Tabelle1.Cells(row + 1, 1).Value <> "" then
if s1 = Tabelle1.Cells(row + 1, 1).Value then row = row + 1
end if
s2 = Tabelle1.Cells(row, 2).Value
. . .
关于, 脚本人