View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default download .csv file indirectly from website - long

A simpler approach might be to do a web query:

Sub AAA_URL_Get_Query()
Dim sStr As String
sStr = "URL;http://moneycentral.msn.com/investor/charts/" & _
"chartdl.asp?Symbol=mrk&DateRangeForm=1&PT=5&C P=1" & _
"&C5=1&C6=1974&C7=1&C8=2004&C9=2&ComparisonsForm=1 " & _
"&CE=0&CompSyms=&DisplayForm=1&D0=1&D5=0&D7=&D6=&D 3=0" & _
"&ShowTablBt=Show+Tablec"

With ActiveSheet.QueryTables.Add(Connection:= _
sStr, _
Destination:=Range("a1"))

.BackgroundQuery = False
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With
End Sub



This brings down the whole page, but you could add code to find the table
and copy it to a new worksheet and delete the old worksheet.

You could also make the symbol value a variable when creating the string.
--
Regards,
Tom Ogilvy

"not2brite " wrote in message
...
I'm trying to create a spreadsheet that when I click a button it will
download the .csv file directly to my harddrive then I can use another
routine to open it after it's downloaded(or better yet open/download
directly) into another sheet in the workbook. My problem is I'm not
sure if, for the given site, I need to learn xml or javascript. I've
seen many references to xml on the forums but the site appears to use
java script.

Here is a piece of code I was able to make work by reading the posts
here and a book called "Excel 2000 Power Programming"

<code
----------------------------------
Function GetDataButton()

Dim DataHere As Range
Dim msn As QueryTable
Dim address As String

Set DataHere = Worksheets("Sheet1").Range("$F1")

address = "URL;http://tinyurl.com/2r7l6"

Sheets("Sheet1").Select
Set msn = ActiveSheet.QueryTables.Add(Connection:=address,
Destination:=DataHere)
msn.Refresh

End Function
----------------------------------
</code

Please note this code DOES NOT do what I want(and the ticker symbol is
hardcoded into it) but it does link to the page where I then have the
option to save it.
My problem is I can't see for the life of me a url to the .csv file.
Here's a snip:

<code
----------------------------
<SCRIPT LANGUAGE=javascript
<!--//
document.QlistCtl.Symbol.focus();document.QlistCtl .Symbol.select();
//--
</SCRIPT
</TR<TR<TD VALIGN=TOP<TABLE WIDTH=100% BORDER=0 CELLSPACING=0
CELLPADDING=0<TR<TD VALIGN=TOP
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 ALIGN=LEFT WIDTH=400

<FORM NAME=Charts ACTION=chartdl.asp METHOD=GET
<TR
<TD ALIGN=RIGHT WIDTH=307
<INPUT TYPE=IMAGE name="FileDownLoadBt" SRC="images/downlbut.gif"
border=0 WIDTH=90 HEIGHT=20
</TD
<TD WIDTH=8<SPACER TYPE=BLOCK WIDTH=8</TD
<TD ALIGN=RIGHT WIDTH=90
<INPUT TYPE=IMAGE name="ShowChartBt" SRC="images/showchrt.gif"
border=0 WIDTH=90 HEIGHT=20
<INPUT TYPE=HIDDEN NAME="Symbol" VALUE="mrk"

</TD
</TR
</FORM
</TABLE
<BR CLEAR=ALL
<BMerck & Co Inc</B
<BR CLEAR=ALL

<!-- Begin stock History table --
--------------------------------
</code

Is this line -
document.QlistCtl.Symbol.focus();document.QlistCtl .Symbol.select();
telling the page/browser what to do if either the download file button
or show chart button is pressed? If it is then it appears I'm going to
need to get a grasp of javascript to be able to see what it's doing.
Once I know that, is that where the XML stuff comes in? Basically
trying to send the page/server/whatever info as if it came from the
webpage and the page "responds" accordingly? I glossed over a book at
the store on xml but I didn't see any refernce to working within vba
code but I could have easily missed it.

It's been 6-7 years since I've messed with html(a passing interest). I
never bothered to learn vbscript or javascript. I've been using excel
for a few months to run numbers on stocks and basically cut/paste the
info I want but that's getting old. I've written some simple subs and
functions up to this point is all. I just started this project Tuesday
so I've still got alot more learning to do but that's where the fun
is.

Thanks for any input,
Brad


---
Message posted from http://www.ExcelForum.com/