excel VBScript,单击保存继续脚本

wz3gfoph  于 2023-06-25  发布在  其他
关注(0)|答案(2)|浏览(119)

当我尝试使用VBA/VBS宏和SAP GUI脚本自动执行过程时,VBScript出现了问题。
它在VBS中输入合同编号,并在SAP ERP交易代码VA03中进行一些标准化更改,但对于某些信息不完整,则会出现此弹出窗口:

我只希望我的脚本单击保存并继续,以防这种情况发生在某个合同号。
它不适用于Applications.DisplayAlerts = False,而且我猜它也不适用于错误处理程序,因为实际上这不是一个错误。
应该是一个简单的IF语句,但我不知道该如何措辞。
有没有人能帮帮我,我在网上的研究让我无处可去:(
代码(虽然它是工作,我只需要一个将处理上述塞子一块):

today = Format(Date, "dd.mm.yyyy")
   Application.DisplayAlerts = False
   'We declared the variables for the while function in excel
    Dim cont As String
    Dim row As Integer
Dim rep As String

Dim j As Integer
j = 2

'Those are the commands with which we make SAP available for the VBA code
Set SapGuiAuto = GetObject("SAPGUI")
  Set SAPApp = SapGuiAuto.GetScriptingEngine
  Set SAPCon = SAPApp.Children(0)
  Set Session = SAPCon.Children(0)

  If IsObject(WScript) Then
   WScript.ConnectObject Session, "on"
   WScript.ConnectObject Application, "on"
 End If
 
Session.findById("wnd[0]").maximize
Session.findById("wnd[0]/tbar[0]/btn[3]").press
Session.findById("wnd[0]/tbar[0]/btn[3]").press
Session.findById("wnd[0]/tbar[0]/okcd").Text = "va42"
Session.findById("wnd[0]").sendVKey 0

'We start the loop inside the macro book and give values to our variables
With ThisWorkbook
While Cells(j, 1) <> ""
cont = Cells(j, 1).Value
row = Cells(j, 3).Value
rep = Cells(j, 4).Value

' enter VBS code
'In this part we change the inst to REMV
Session.findById("wnd[0]").maximize
Session.findById("wnd[0]/usr/ctxtVBAK-VBELN").Text = cont
Session.findById("wnd[0]/usr/ctxtVBAK-VBELN").caretPosition = 8
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01/ssubSUBSCREEN_BODY:SAPMV45A:4426/subSUBSCREEN_TC:SAPMV45A:4908/tblSAPMV45ATCTRL_U_ERF_KONTRAKT/ctxtVBAP-KDMAT[5," & CStr(row) & "]").SetFocus
Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01/ssubSUBSCREEN_BODY:SAPMV45A:4426/subSUBSCREEN_TC:SAPMV45A:4908/tblSAPMV45ATCTRL_U_ERF_KONTRAKT/ctxtVBAP-KDMAT[5," & CStr(row) & "]").caretPosition = 6
Session.findById("wnd[0]").sendVKey 2

'change date
Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\03").Select
Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\03/ssubSUBSCREEN_BODY:SAPLV45W:4201/ctxtVEDA-VDEMDAT").Text = today
Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\03/ssubSUBSCREEN_BODY:SAPLV45W:4201/ctxtVEDA-VDEMDAT").SetFocus
Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\03/ssubSUBSCREEN_BODY:SAPLV45W:4201/ctxtVEDA-VDEMDAT").caretPosition = 10

'change INST to REMV
Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\10").Select
Session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4454/ctxtVBAP-KDMAT").Text = rep

'Deletes the first line in Technical Objects and saves the changes
Session.findById("wnd[0]/mbar/menu[3]/menu[9]").Select
Session.findById("wnd[0]/usr/tblSAPLIWOLOBJK_220").getAbsoluteRow(0).Selected = True
Session.findById("wnd[0]/tbar[1]/btn[19]").press
Session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
Session.findById("wnd[0]/tbar[0]/btn[3]").press
Session.findById("wnd[0]/tbar[0]/btn[11]").press

'we make sure the loop goes through every row and then end it
j = j + 1
Wend

End With
End Sub

最好的问候,米哈伊尔

y1aodyip

y1aodyip1#

首先,我会记录vbs程序中缺少的部分。然后,你必须认识到在主程序中必须安装这个部分。但我怀疑这会发生在储蓄之后。粗略的结构可能看起来像这样:

. . .
Session.findById("wnd[0]/tbar[0]/btn[11]").press
'------------------------------ new ---------------------------
on error resume next
'Suppose that's the missing piece of program
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
on error goto 0
'------------------------------ new ---------------------------
'we make sure the loop goes through every row and then end it
j = j + 1
Wend
. . .

问候,ScriptMan

l7wslrjt

l7wslrjt2#

我添加了上面Script man提出的解决方案!效果很好!

相关问题