首页 > 解决方案 > 我需要在宏中写什么来对 SAP 中的突然提示进行排序?

问题描述

所以我有一个更新 SAP 价格的宏。它逐个单元格复制并按顺序执行更新顺序,但有时,在执行更新并保存订单以使用下一行之后,SAP 中会出现提示,我需要单击是或否,或接受/拒绝。

然后我的宏停止,因为它没有一行代码可以对其进行操作。我确实知道需要哪一行,但我的问题是如何编写一行代码,如果出现提示则将执行该代码行?

请记住,有时它会弹出,有时不会。

这是我的代码:

Public sessioninfo As SAPFEWSELib.GuiSessionInfo


Public Sub fastPFI()
Dim ws As Worksheet
Dim App As SAPFEWSELib.GuiApplication
Dim sor As Long
Dim maxsor As String

'HOEEUBV2 (EUB with scripting)
  Set GuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
  Set App = GuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
  Set Con = App.Children(0) 'Get the first system that is currently connected
  Set session = Con.Children(0) 'Get the first session (window) on that connection
    Set sessioninfo = session.Info

Set ws = Excel.ThisWorkbook.Worksheets("system")
sor = 2
maxsor = ws.Cells(Rows.Count, 1).End(xlUp).Row
'maxsor = 3
Do While sor < maxsor + 1

session.StartTransaction "va02"
'session.FindById("wnd[0]").SendVKey 0
session.FindById("wnd[0]/usr/ctxtVBAK-VBELN").Text = Cells(sor, 1)
session.FindById("wnd[0]").SendVKey 0
session.FindById("wnd[1]").SendVKey 0
session.FindById("wnd[0]").SendVKey 30
session.FindById("wnd[0]").SendVKey 11
session.FindById("wnd[0]/usr/lblRV45S-BSTNK").SetFocus
session.FindById("wnd[0]/usr/lblRV45S-BSTNK").CaretPosition = 18
'session.FindById("wnd[0]").SendVKey 0

sor = sor + 1


Loop

MsgBox "All proformas have been created" & vbNewLine & "Click OK to close file"

' Application.DisplayAlerts = False
'ActiveWorkbook.Close Savechanges:=False
'Application.DisplayAlerts = True

End Sub```

标签: vbasapui5prompt

解决方案


On Error GoTo Next在可能或不会发生的代码行解决了它之后。


推荐阅读