Webquery - Excel 2003

K

kanind

I am using the following script to get the stock quote from yahoo financial
website. This script works fine in my office PC but the same script returns
Run-time error '1004' in my home PC. Both the places I am using Excel 2003
SP2 and Windows XP Professional Version 2002 Service Pack 2:

Sub GetStockQuotes()
With
ActiveWorkbook.ActiveSheet.QueryTables.Add(Connection:="URL;http://in.finance.yahoo.com/d/quotes.csv?s=ASHOKLEY.NS&f=l1",
Destination:=ActiveSheet.Cells(1, 1))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
End Sub

Please advice me how to get rid of the Error.
 
D

Don Guillett

Try it this way. You may want to replace the actual symbol with a variable


Sub GetStockQuotes()
With ActiveWorkbook.ActiveSheet _
..QueryTables.Add(Connection:= _
"URL;http://in.finance.yahoo.com/d/quotes.csv?s=" & _
"ASHOKLEY.NS&f=l1", Destination:=ActiveSheet.Cells(1, 1))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With

'to delete name buildup
For Each N In ActiveSheet.Names
N.Delete
Next N
End Sub
===========================
With Sheets(2).QueryTables.Add(Connection:="URL;" _
& "http://finance.yahoo.com/d/quotes.csv?s=" & _
symbols & "&f=snd1t1l1ohgpvqyd&e=.csv", _
Destination:=Sheets("Data").Range("b2"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
 
K

kanind

As recommended by NickHK, I tried with other ISP Internet connection, now the
script works fine. Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top