Consulting

Results 1 to 8 of 8

Thread: Automating download from IE SaveAs form

  1. #1
    VBAX Newbie
    Joined
    Jun 2006
    Posts
    4
    Location

    Unhappy Automating download from IE SaveAs form

    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!!

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    could you be a little more specific about 'file' - html, image, pdf??? And, are you using the InternetExplorer.Application Object, or sendkeys.... ??

    .02
    Stan

  3. #3
    VBAX Newbie
    Joined
    Jun 2006
    Posts
    4
    Location
    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.

  4. #4
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

  5. #5
    VBAX Newbie
    Joined
    Jun 2006
    Posts
    4
    Location
    well actually the link is something like this....

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

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

  6. #6
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

  7. #7
    VBAX Newbie
    Joined
    Jun 2006
    Posts
    4
    Location
    I'm not sure if i am following you??

  8. #8
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by bkholy
    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/crCo...dType=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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •