Home > database >  How create a time/pause in SAP GUI
How create a time/pause in SAP GUI

Time:10-15

After I connect to SAP GUI via Excel, I'm having problems acquiring data from SAP GUI, because the macro is very fast, because I did the tests that if it is paused in some moments, the logic works correctly, but without times, it doesn't work. So I would like to include time when running in SAP GUI, but I don't know the correct code to do this.

Sub Sap()

Dim Application, SapGuiAuto, Connection, session, WScrip

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
'Login
session.findbyid("wnd[0]").maximize
session.findbyid("wnd[0]/usr/txtRSYST-BNAME").Text = "mylogin"
session.findbyid("wnd[0]/usr/pwdRSYST-BCODE").Text = "password"
session.findbyid("wnd[0]/usr/pwdRSYST-BCODE").SetFocus
session.findbyid("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 8
session.findbyid("wnd[0]").sendVKey 0
'MM02
session.findbyid("wnd[0]/tbar[0]/okcd").Text = "mm02"
session.findbyid("wnd[0]").sendVKey 0
Application.Wait Now   TimeValue("00:00:03") '——->>>>> BUT NOT WORK THIS FUNCTION

'continueing…

End Sub

CodePudding user response:

There is also another way to generate a wait in VBA.

for example:

Sub Sap()

Dim Application, SapGuiAuto, Connection, session, WScript
set wshell = CreateObject("Wscript.Shell")
...
wshell.run "c:\tmp\sleep_3000.vbs",1,true
'continueing…
End Sub

sleep_3000.vbs in c:\tmp

wscript.sleep 3000

Regards, ScriptMan

  • Related