运行时错误 619 找不到指定的控件 ID

12 浏览
0 Comments

运行时错误 619 找不到指定的控件 ID

我在VBA中编写了以下代码。

当进入for...next循环处理订单时,如果报告包含数据,它能正常工作。但是对于不包含数据的订单,VBA会给出以下错误提示:

运行时错误 '619': 无法通过ID找到该控件。

SAP GUI Run-time error '619': The control could not be found by id.

当我从空订单的那一行开始执行宏时,宏会跳转到line1这一行,但是如果下一个订单没有数据,宏将停止工作。

它停在这一行上:

session.findById("wnd[0]/shellcont/shell/shellcont[2]/shell").hierarchyHeaderWidth = 453

你能帮忙吗?

代码:

Sub sales_status_kpi()
Application.ScreenUpdating = False
    SheetSrc = "Input data"
    On Error Resume Next
    If Not IsObject(SAPApplication) Then
        Set SapGuiAuto = GetObject("SAPGUI")
        If Err.Number <> 0 Then Exit Sub
        Set SAPApplication = SapGuiAuto.GetScriptingEngine
        If Err.Number <> 0 Then Exit Sub
    End If
    If Not IsObject(Connection) Then
        Set Connection = SAPApplication.Children(0)
        If Err.Number <> 0 Then
            MsgBox ("请打开SAP!")
            Exit Sub
        Else
        End If
    End If
    If Not IsObject(session) Then
        Set session = Connection.Children(0)
    End If
    On Error GoTo 0
    Application.Wait (Now + TimeValue("0:00:01") / 1.5)
    Dim i As Double
    Dim last_row As Double
    last_row = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 11 To last_row
    session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/Ns_alr_87013019"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/txt$6-KOKRS").Text = "EU01"
session.findById("wnd[0]/usr/ctxt_6ORDGRP-LOW").Text = Cells(i, 1)
session.findById("wnd[0]/usr/ctxt_6ORDGRP-LOW").SetFocus
session.findById("wnd[0]/usr/ctxt_6ORDGRP-LOW").caretPosition = 6
session.findById("wnd[0]/tbar[1]/btn[8]").press
On Error GoTo line1
session.findById("wnd[0]/shellcont/shell/shellcont[2]/shell").hierarchyHeaderWidth = 453
session.findById("wnd[0]/usr/lbl[62,8]").SetFocus
session.findById("wnd[0]/usr/lbl[62,8]").caretPosition = 9
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[1]/usr/lbl[1,2]").SetFocus
session.findById("wnd[1]/usr/lbl[1,2]").caretPosition = 4
session.findById("wnd[1]").sendVKey 2
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellColumn = "BELNR"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectedRows = "0"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectContextMenuItem "&XXL"
session.findById("wnd[1]/usr/cmbG_LISTBOX").SetFocus
session.findById("wnd[1]/usr/cmbG_LISTBOX").Key = "31"
session.findById("wnd[1]/tbar[0]/btn[0]").press
Dim path As String
path = Cells(2, 6)
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = path
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = Cells(i, 1).Value & ".XLSX"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 10
session.findById("wnd[1]/tbar[0]/btn[0]").press
Cells(i, 2) = "文件已生成"
line1:
Next i
End Sub

0