user10957064
user10957064

Reputation: 9

back to SAP initial screen from VBA

I have an excel macro that uses SAP-code created by the built in sap-scripting. It works fine, but I need to perform those steps more than once on different tables. The problem I have is that I cannot simply trigger the first step, as at that moment the reference for the given screen not valid, first I would need to get the initial screen in order to do so, but I cannot figure out how to do that.

I tried to record the "back" action from SAP Gui, but these actions seem to be not the same each time, I cannot rely on them. ON sap related sites I found how to refer to screens, but I don't know how could I utilize it in my code. One of the way is: session.findById("wnd[0]").Name

Sub SimpleSAPExport()
' attach to sap  session
Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object 
Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP 
GUI Set SAPCon = SAPApp.Children(0) 
Set session = SAPCon.Children(0)
If Not IsObject(session) Then   MsgBox "nok"
End If
'start transactiom
session.FindById("wnd[0]/tbar[0]/okcd").Text = "BPMDG/UTL_BROWSER" 
session.FindById("wnd[0]/tbar[0]/btn[0]").Press 
session.FindById("wnd[0]").Maximize
session.FindById("wnd[0]/usr/ctxtP_TABNAM").Text = "ska1"
'.
'.
session.FindById("wnd[1]/usr/ctxtDY_PATH").Text = "c:\vba\sapgui\"   
session.FindById("wnd[1]/usr/ctxtDY_FILENAME").Text = "ska1-oa01.txt"
' would need to go start transaction-part

Upvotes: 0

Views: 2059

Answers (1)

ScriptMan
ScriptMan

Reputation: 1625

You could try the following:

...
session.FindById("wnd[0]/tbar[0]/okcd").Text = "/nBPMDG/UTL_BROWSER" 
session.FindById("wnd[0]/tbar[0]/btn[0]").Press 
...

Regards, ScriptMan

Upvotes: 0

Related Questions