VBA - Can't get to download a file

Ooalkman

New Member
Joined
Oct 23, 2014
Messages
7
Hi there !

I would like to download a file from a website using VBA. The tricky part is that the file is generated after filling a form in the webpage and clicking on the submit button, so I don't know its name and address before download (meaning I can't use the URLDownloadToFile API). I've tried several things, so far I've got two problems :

  1. Using a XMLHTTP request (as in this thread), I can't get to do the right request to trigger the download. I think the dynamic form is reading the webpage before submitting, adding some variables and I don't know how to simulate that with my request.
  2. Using a HTMLDocument with IE, I manage to trigger the download but I can't download automatically, I have to interfere manually (and I'd like the app to run background which doesn't seem possible this way).
So anybody has a clue on this ? I have to admit i'm getting a little depressed. :(
 
Victory ! I managed to download a readable file by errasing the
Code:
WinHttpReq.setRequestHeader "Accept-Encoding", "gzip,  deflate"
request. I was actually downloading gzip. I don't know in which part of the process the gzip is extracted and converted but the thing works now anyway.

Now I just have to solve my "timed out" problem. Oh, and I figured out it didn't work if I didn't send the good cookies requests, so I'm gonna have to find out automatically what thoses cookies are too. But hey, there's progress !
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,606
Messages
6,125,800
Members
449,261
Latest member
Rachel812321

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top