em2 Registered User


I am trying to code a VBA macro in Excel that will automatically download the csv file when clicking on the CSV icon on the following website:


I have been able to download the page itself into Excel but not the actual csv file. Would anyone be able to help me or point me in the right direction?


srsly78 Registered User

Well since you have it already in excel you can just go sheet .saveas(format_CSV) or something very similar.

em2 Registered User


I only have the actual page which gives 3 days data but I need all the data in the CSV file which isn't displayed on the webpage...

srsly78 Registered User

Easy, just hack into the website and steal all their data so.

Serious answer: If the CSV file is not made available then you can't download it. What you can do is download a chunk each day and slowly aggregate these together.

em2 Registered User

The CSV is available to 'Open' or 'Save' if you click on the CSV link on the website, I just don't know how to code for this in Excel VBA so that a macro will do it automatically...

srsly78 Registered User

Ah right, well do this so: http://stackoverflow.com/questions/3963475/http-post-in-vba

Just emulate whatever http request the save command is doing.

em2 Registered User

Not sure how to do this...

srsly78 Registered User

Copy and paste the vba. It shows you how to use the vba http library. You can do a http post the same as what clicking the save button does.

More useful stuff here: http://www.mrexcel.com/forum/excel-questions/67123-visual-basic-applications-save-file-website.html

em2 Registered User

No luck with any of the links unfortunately, I still don't know how to apply the code to download the file.

This is the code I can see from the website:

"<inputname="formatoCSV"id="formatoCSV"type="image"src="/SieInternet/img/ConsultarDirectorio/formato_CSV.png"onclick="document.consultarDirectorioActionForm.target='_self'; return onClickConsultar() "hl_hint="return '<div class=\'hint\'>Export the selected series <br>in comma-separated values format (CSV).</div>'"onmouseover="hl_show(event); document.getElementById('formatoCSV').alt='';"alt="Export the selected series in comma-separated values format (CSV)."class="botonFormato">"

Apologies if I haven't posted this code correctly to this board!

srsly78 Registered User

What you are looking for is the http post request that happens when you click the save button. I don't think that is in the snippet you posted. This isn't my area of expertise, maybe a web developer could give you better advice.

Once you do find the post request however, you can use the vba stuff I linked earlier to download the file.

em2 Registered User

Thanks anyway for your posts.

It could be from here:

"<form name="consultarDirectorioActionForm" method="POST" action="/SieInternet/consultarDirectorioInternetAction.do?accion=consultarSeries" target="_blank"><table border="0" width="984" style="padding:0px 20px 0px 20px;background:white; margin: 0 auto" cellpadding="0" cellspacing="0" align="center"><tr><td><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><a href="http://www.banxico.org.mx"><img id="imagen-encabezado" src="http://www.banxico.org.mx/apps_header.png" height="74" width="1024" border="0" style="margin-bottom: 15px;">"

srsly78 Registered User

em2 Registered User

Still no joy with this code... Can anyone else please help?

srsly78 Registered User

I basically did 99% of it for you -.-

Which bit do you have trouble with?

em2 Registered User

All of it, I can't get past the internet page to download the csv file

Want to share your thoughts?

Login here to discuss!