【问题标题】:VBScript, click save to continue ScriptVBScript,点击保存继续脚本
【发布时间】:2018-06-27 08:20:14
【问题描述】:

当我尝试使用 VBA/VBS 宏自动执行过程时,我遇到了一个 VBScript 问题。

在VBS中输入一个合同号,在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

最好的问候, 米哈伊尔

【问题讨论】:

    标签: vba excel vbscript sap


    【解决方案1】:

    首先,我将记录丢失的 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
    . . .
    

    问候, 脚本人

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-26
        • 1970-01-01
        • 1970-01-01
        • 2023-01-25
        • 1970-01-01
        相关资源
        最近更新 更多