I use vbscript to run SAP GUI via Excel VBA, the following is my actions:
- Login
- select Tcode
- give data and execute
- export as worksheets. My question is that the last action (export as worksheets) will show a file dialog that I need to choose path and press. But I want to export automatically by my set path and filename without the "save as" dialog.
Is there any method to do that?
Here is my VBA code:
Dim SAPconn As Object
Dim SAPsession As Object
Dim SapGuiAuto As Object
Dim WshShell As Object
Shell "C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe", 4
Set WshShell = CreateObject("WScript.Shell")
Do Until WshShell.AppActivate("SAP Logon ")
Application.Wait Now + TimeValue("0:00:01")
Loop
Set WshShell = Nothing
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPapp = SapGuiAuto.GetScriptingEngine
Set SAPconn = SAPapp.Openconnection("ConnectionsName", True)
Set SAPsession = SAPconn.Children(0)
'LOGON
SAPsession.findById("wnd[0]").maximize
SAPsession.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "100"
SAPsession.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "userid"
SAPsession.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "password"
SAPsession.findById("wnd[0]").sendVKey 0
SAPsession.findById("wnd[0]/tbar[0]/okcd").Text = "tcode"
SAPsession.findById("wnd[0]").sendVKey 0
'run the script(skip)
SAPsession.findById("wnd[0]/usr/ctxtWERKS-LOW").Text = Cells(1, 2)......
'execute
SAPsession.findById("wnd[0]/tbar[1]/btn[8]").press
'show list
SAPsession.findById("wnd[0]/tbar[1]/btn[48]").press
'export
SAPsession.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").Select
'↑ just select export>as worksheet and open the file dailog....