[英]Excel SAP GUI Compile error label not defined
我有這個我記錄的 SAP GUI 腳本,如下所示。 宏應該能夠將其導出到 excel 工作表。 但是,我需要一種方法來實際填充 excel 表。 但是我不斷收到此錯誤:未找到 label。 有人可以幫我嗎? 我在這里看到了這個問題: How to run SAP GUI script from Excel Macro
但是,我幾乎完全相同地遵循它,我正在嘗試解決我搞砸的地方。
原始 SAP 宏記錄器:
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
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]/okcd").text = "ZPRS"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtP_PLANT").text = "1707"
session.findById("wnd[0]/usr/ctxtS_ARBPL-LOW").text = "BSLSR"
session.findById("wnd[0]/usr/ctxtS_ARBPL-LOW").setFocus
session.findById("wnd[0]/usr/ctxtS_ARBPL-LOW").caretPosition = 5
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
查看鏈接並將其更改為我認為正確的內容
Private Sub CommandButton1_Click()
On Error GoTo Err_NoSAP
If Not IsObject(SAPGuiApp) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPGuiApp = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPGuiApp.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject SAPGuiApp, "on"
End If
If (Connection.Children.Count > 1) Then GoTo Err_TooManySAP
Set aw = SAP_session.ActiveWindow()
aw.findById("wnd[0]").Maximize
On Error GoTo Err_Description
session.findById("wnd[0]").Maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "ZPRS"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtP_PLANT").Text = "1707"
session.findById("wnd[0]/usr/ctxtS_ARBPL-LOW").Text = "BSLSR"
session.findById("wnd[0]/usr/ctxtS_ARBPL-LOW").SetFocus
session.findById("wnd[0]/usr/ctxtS_ARBPL-LOW").caretPosition = 5
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
Exit Sub
End Sub
但后來我收到錯誤消息:
編譯錯誤:label 未定義
有沒有人對如何糾正這個有任何想法?
好吧,乍一看,您正在使用像On Error GoTo Err_NoSAP
這樣的錯誤處理程序。 在您發布的代碼行中沒有任何地方帶有錯誤處理程序,例如Err_NoSAP:
,代碼應該在發生錯誤后跳轉到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.