我使用vbscript通过Excel VBA运行SAP,以下是我的操作::Login>select Tcode>give data and execute>export as worksheets.My question is that the last action (export as worksheets) will show a fileialog that I need to choose path and press. 但我想通过我设置的路径和文件名自动导出,而不需要saveas对话框。
有什么方法可以做到这一点吗?这是我在VBA中的代码。
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....
这是我用来从SAP保存的代码--元素的确切路径。
(例如 "wnd[1]/usr/ctxtDY_PATH"
)将与你的情况不同,因为这取决于你正在使用什么表。
SAPsession.findById("wnd[1]/tbar[0]/btn[0]").press
SAPsession.findById("wnd[1]/usr/ctxtDY_PATH").Text = "C:\Downloads\"
SAPsession.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "Downloaded_file_name"
SAPsession.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 13
SAPsession.findById("wnd[1]/tbar[0]/btn[11]").press
这将做如下操作。
据我所知,完全绕过保存对话框是不可能的。