|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
可以这样改写一下
- Sub 建立钢料pr()
- '忽略错误
- On Error Resume Next
- '从excel模板数量建立到sap pr数量,下面为sap录屏脚本,使用excel中的变量且循环
- If Not IsObject(Applicationa) Then
- Set SapGuiAuto = GetObject("SAPGUI")
- Set Applicationa = SapGuiAuto.GetScriptingEngine
- End If
- If Not IsObject(Connection) Then
- Set Connection = Applicationa.Children(0)
- End If
- If Not IsObject(SessionB) Then
- Set SessionB = Connection.Children(0)
- End If
- If IsObject(WScript) Then
- WScript.ConnectObject SessionB, "on"
- WScript.ConnectObject Applicationa, "on"
- End If
- Row = Application.CountA(ActiveSheet.Range("F:F"))
- '
- For I = 2 To Row
- If Cells(I, 6) = "" Then
- Exit Sub
- Else
- With SessionB
- .findById("wnd[0]").maximize
- .findById("wnd[0]/tbar[0]/okcd").Text = "/nME51N"
- .findById("wnd[0]").sendVKey 0
-
- .findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0016/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").modifyCell 0, "MATNR", Cells(I, 6)
- .findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0016/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").modifyCell 0, "MENGE", Cells(I, 8)
- .findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0016/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").modifyCell 0, "EEIND", Cells(I, 11)
- .findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0016/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").modifyCell 0, "EKGRP", Cells(I, 15)
- .findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0016/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").modifyCell 0, "FLIEF", Cells(I, 19)
-
- .findById("wnd[0]").sendVKey 0
- str_text = .findById("wnd[0]/sbar").Text '状态栏消息文本
-
- If str_text Like "" Then '返回是否成功消息
- .findById("wnd[0]/tbar[0]/btn[11]").press
- ActiveSheet.Cells(I, 22).Value = .findById("wnd[0]/sbar").Text
- .findById("wnd[0]/tbar[0]/btn[3]").press
- Else
- ActiveSheet.Cells(I, 22).Value = .findById("wnd[0]/sbar").Text
- End If
- End With
- End If
- Next I
- On Error GoTo 0
- MsgBox "建立完成,请完成后续作业"
- End Sub
复制代码
|
-
|