PDA

View Full Version : Automating download from IE SaveAs form



bkholy
06-09-2006, 10:02 AM
I'm running into a problem to automate a process where my program can download a specified file. I have my VBA code point to the file but when the SaveAs box comes up I don't know what to do from that point on. Please someone help me!!

stanl
06-09-2006, 11:02 AM
could you be a little more specific about 'file' - html, image, pdf??? And, are you using the InternetExplorer.Application Object, or sendkeys.... ??

.02
Stan

bkholy
06-09-2006, 11:12 AM
Basically what happens is i have the internetexplorer object go to a download link. The link is to a .CSV file, in which then a file download box pops up, my options are to open it, save it, or cancel. What i want the program to do is click on save and save to a specified location. Not sure if i should use windows API for this one or if there is a better method.

stanl
06-09-2006, 11:48 AM
Is this a secure site? I would use CreateObject("MSXML2.XMLHTTP") especially if you have a url reference to the .csv file.

Stan



'pseudo-code
oHTTP = CreateObject("MSXML2.XMLHTTP")
cURL = "http://www.mysite/myfile.csv
oHTTP.open "GET", cURL, False
oHTTP.send ""
oStream = CreateObject("ADODB.Stream")
oStream.Type = 0 'ascii
oStream.Open
oStream.Write oHTTP.responseBody
oStream.SaveToFile "mycsvfile" ,2
oStream.close
oStream=Nothing
oHTTP=Nothing

bkholy
06-09-2006, 11:51 AM
well actually the link is something like this....

"https://workbench.mellon.com/cr/crControl/ViewReportOutput?documentID=4130669&transformType=csvWithHeader&reportInstanceId=5480739&downloadType=download"

So i don't think i can use the xml commponent, any other suggestions?

stanl
06-09-2006, 12:09 PM
That is why I asked 'Is it a secure site' - you can use an HTTP POST rather than GET w/login and pwd info.

Stan

bkholy
06-09-2006, 12:21 PM
I'm not sure if i am following you??

stanl
06-11-2006, 04:57 AM
I'm not sure if i am following you??

In my experience, unless HTTP protocol is turned off by the server, either binary or ascii files can be obtained. If I just try to navigate to the URL you supplied I end up with a login screen. You might try something basic like



myfile = "C:\temp\test.txt"

cURL =https://workbench.mellon.com/cr/crControl/ViewReportOutput?documentID=4130669&transformType=csvWithHeader&reportInsta nceId=5480739&downloadType=download

;note the object change, this has less overhead than
;msxml2.http
WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
WinHttpReq.SetCredentials "userid", "password", ""
WinHttpReq.Open("GET", cURL, False)
WinHttpReq.Send ""
oStream = CreateObject("ADODB.Stream")
oStream.Type = 0 'ascii
oStream.Open
oStream.Write WinHttpReq.responseText
oStream.SaveToFile myfile ,2
oStream.close
oStream=Nothing
WinHttpReq=Nothing


where userid and password are what you use to login. Worse case you cannot connect and myfile will contain nothing; or it will contain html code with an error, or the downloadType=Download parameter forces the saveas box.

It is difficult from the outside of https to diagnose what is on the inside.
Stan