Automating Downloading of Data from Bank of England website

Lucas in London

Board Regular
Joined
Jun 17, 2002
Messages
88
Hey,

I've seen this stuff being done for other websites but I just don't know how to do it. Does nyone have a macro that I could modify/use to download exchange rate data in the form of an Excel spreadsheet from the bank of england website from the following link:

http://213.225.136.206/mfsd/iadb/fr...&CSVF=TT&FN=N&C=ECW&excel97.x=17&excel97.y=23

Also if you could briefly explain to me how the code works so that I could change it to download other data series would be grateful.

Many thanks

Lucas
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi

Indeed, the spreadsheet downloaded but I want to know how to automate this even further in a couple of respects:

1) I want Excel to automatically download the spreadsheet to the c drive without any interaction from the user e.g. clicking on save or open etc.

2) I also want to download data for other series in one go. Ideally I want to store several codes in the excel sheet (XUDLGBD in the current case) and run a macro that will download all spreadsheets for each code with the least amount of interaction from the user.

So a sheet in my Excel workbook might look like this:

Code
XUDLGBD
XUDLGPS

I would want excel to download spreadsheets for each one of these codes after clicking on a macro. One problem is I see no reference to each one of these codes in the URL link so am confused how the URL link can be manipulated to refer to each different series.

Hope all this makes sense.

Thanks.

Thanks

Lucas
 
Upvote 0
The link may have an expiration and I would not depend on the links unless you have knowledge that they are immutable.

XUDLGBD
&C=DSJ

XUDLGPS
&C=ECW

This is the only argument that varies in the URL's. Also,

excel97.x=23&excel97.y=22

is looking to validate an actual mouse click on the Excel image. You may need to provide random numbers for the x and y coords. If the server keeps getting requests from the same IP and the mouse is always in the exact same position, they may disallow the download. This is a weak method of discouraging automation.

If you have to dissect many of these series codes, there are other alternatives...

Here is the code. See the example download below for usage...

<table border="1" bgcolor="White"><caption ALIGN=left><font size="2" face=Courier New>Example VBA Code:</FONT></caption><tr><td><font size="2" face=Courier New>  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> URLDownloadToFile <font color="#0000A0">Lib</font> "urlmon" <font color="#0000A0">Alias</font> "URLDownloadToFileA" _
        (ByVal pCaller <font color="#0000A0">As</font> Long, _
        <font color="#0000A0">ByVal</font> szURL <font color="#0000A0">As</font> String, _
        <font color="#0000A0">ByVal</font> szFileName <font color="#0000A0">As</font> String, _
        <font color="#0000A0">ByVal</font> dwReserved <font color="#0000A0">As</font> Long, _
        <font color="#0000A0">ByVal</font> lpfnCB <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  
  <font color="#0000A0">Sub</font> DownloadSelection()
     <font color="#0000A0">If</font> Selection.Cells.Count <> 1 <font color="#0000A0">Then</font> <font color="#0000A0">Exit</font> <font color="#0000A0">Sub</font>
     Selection.Offset(, 2) = "Downloading. Please wait..."
     <font color="#0000A0">If</font> URLDownloadToFile(0, "http://213.225.136.206/mfsd/iadb/fromshowcolumns.asp?" & _
         "Travel=NIxSCxSUx&FromSeries=1&ToSeries=50&DAT=RNG&FD=1&FM=Jan&FY=1963&" & _
         "TD=3&TM=Apr&TY=2006&CSVF=TT&FN=N&C=" & Selection.Offset(, 1) & _
         " &excel97.x=23&excel97.y=22", "C:\" & Selection & ".xls", 0, 0) = 0 <font color="#0000A0">Then</font>
         <font color="#008000"> 'ok. Run Excel's query on the local file</font>
          Selection.Offset(, 2) = "Downloaded to: C:\" & Selection & ".xls"
     <font color="#0000A0">Else</font>
         <font color="#008000"> 'failed to save page</font>
          Selection.Offset(, 2) = "Download Failed."
     <font color="#0000A0">End</font> <font color="#0000A0">If</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> CommandButton1_Click()
       DownloadSelection
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table>

DownloadUrlBOE.zip
 
Upvote 0
Hello,

Thanks for the code 'rightclick'. It works great but your suspicions about the roboustness of the links were correct. I am still able to download the file using the same links but the downloaded file contains only old data - i.e. the most recent data values say for the last 10 days are not there. So it seems it's downloading an old file probably based on when the file was originally downloaded. Does this imply there could be something indicative of date field/argument in the link they we could potentially manipulate?Just a thought.

Thanks,

Lucas
 
Upvote 0
The procedure was so short that I did not really bother with an explanation. I simply added the ability to download more than one file and I added some date variable into the URL...
 
Upvote 0
Hi,

Does URLMon support POST methods?

don't want to thread crap, but this is in regards to a Wininet post

BTW... tip for web content in tables: replace {/TR} with breaks, {/TD} with tabs, and then use a regex to replace <[^>], and you can easily split this up into arrays to work with datasets. It's much, much faster than loading it into a worksheet and using the excel convertor for such things.
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,148
Members
449,364
Latest member
AlienSx

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