Hi all,
I have written the following script (with the help of others from this forum, thanks!). When I run through the script (tools->Go) it works. When I execute it from my VBA it works sometimes and not others. When it does not, it seems to not address the "save as" on the browser window but instead operates on the browser address bar instead.
I call the compiled script from my VBA once I have the browser display the "save as" window from my VBA. The script takes in a string for the download dir and file name to save.
RunScript = Shell("C:\My Code\download.exe C:\Test\data.csv")
I then execute this script (compiled)
;read arguments $pathToSave=$CmdLine[1] ; get the handle of main window Local $windHandle=WinGetHandle("[Class:IEFrame]", "") Local $winTitle = "[HANDLE:" & $windHandle & "]"; ;get coordinates of default HWND Local $ctlText=ControlGetPos ($winTitle, "", "[Class:DirectUIHWND;INSTANCE:1]") ; Select save as option WinActivate ($winTitle, "") Send("{F6}") sleep(500) Send("{TAB}") sleep(500) Send("{DOWN}") sleep(500) Send("a") ; Save as dialog ; wait for Save As window WinWait("Save As") ; activate Save As window WinActivate("Save As") ; path to save the file is passed as command line arugment ControlFocus("Save As","","[CLASS:Edit;INSTANCE:1]") Send($pathToSave,1) sleep(500) ;click on save button ControlClick("Save As","","[TEXT:&Save]")
Any ideas of what I am doing wrong pls. I need this step robust and reliable, but it seems more like lottery at the moment... also, is there a way of making it work regardless of focus on window? That is I have to leave PC unattended/untouched for it to work (when it does!). Thanks
M