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?
Well since you have it already in excel you can just go sheet .saveas(format_CSV) or something very similar.
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...
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.
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...
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.
Not sure how to do this...
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
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!
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.
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;">"
Still no joy with this code... Can anyone else please help?
I basically did 99% of it for you -.-
Which bit do you have trouble with?
All of it, I can't get past the internet page to download the csv file