Предположим, у вас есть некоторый код автоматизации SAPGUI, подобный этому
' This is the last line where you trigger some action within SAPGUI
.findById("wnd[1]/usr/....
' Let's assume this line triggers the download and with it the Windows dialog box
.findById("wnd[1]/tbar[0]/btn[0]").press
Затем вам нужно добавить вызов скрипта vba непосредственно перед строкой, в которой запускается диалоговое окно Windows, то есть
' This is the last line where you trigger some action within SAPGUI
.findById("wnd[1]/usr/....
dim SaveAs as string
dim xlFile as string
SaveAs ="Full Path to SaveAs.Vbs"
xlFile = "Full Path to the xls file"
Shell "wscript " & SaveAs & xlFile & " Save as"
' Let's assume this line triggers the download and therefore the WIndows dialog box
.findById("wnd[1]/tbar[0]/btn[0]").press
Сценарий SaveAs.vbs может выглядеть следующим образом
' WScript.Echo WScript.Arguments.Count
if Wscript.Arguments.count > 0 then
' This first section deletes the file if it already exists, to avoid a prompt to overwrite.
set fs = CreateObject("Scripting.FileSystemObject")
if fs.fileExists(WScript.arguments(0)) then
Set myfile = fs.GetFile(WScript.arguments(0))
myfile.Delete
end if
'this loop runs until the Save As window finally appears
set Wshell = CreateObject("WScript.Shell")
Do
' Argument 1 must be the excat caption of the Save As dialogbox:
bWindowFound = Wshell.AppActivate(WScript.arguments(1))
WScript.Sleep 1000
Loop Until bWindowFound
Wshell.appActivate WScript.arguments(1)
Wshell.sendkeys "%n" ' <= Keyboard short cut for Alt-n, you might need to change the n to your shortcut
WScript.Sleep 400
Wshell.sendkeys WScript.arguments(0)
Wshell.sendkeys "%s" ' <= Keyboard short cut for Alt-s, you might need to change the n to your shortcut
WScript.Sleep 400
end if