em2 Registered User
#1

Hi,

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:

http://www.banxico.org.mx/SieInternet/consultarDirectorioInternetAction.do?accion=consultarCuadro&idCuadro=CF102&sector=6&locale=en

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?

Thanks

srsly78 Registered User
#2

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

em2 Registered User
#3

Hi,

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
#4

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
#5

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
#6

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

Not sure how to do this...

srsly78 Registered User
#8

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
#9

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
#10

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
#11

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
#12

em2 Registered User
#13

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

srsly78 Registered User
#14

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

Which bit do you have trouble with?

em2 Registered User
#15

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!