automate yahoo finance query refresh from html

L

Legacy 266325

Guest
Hello

I am using the following code to import historical indices data for 5 different indexes in yahoo finance.

Public Sub Import_Yahoo_Finance_Historical()

Dim URL As String
Dim dateParams As String

'Date ranges from default earliest Yahoo start date (m/d/y) to current date (m/d/y)

dateParams = "&a=0&b=3&c=1977&d=" & Month(Date) - 1 & "&e=" & Day(Date) & "&f=" & Year(Date)

'Daily prices

URL = "http://ichart.finance.yahoo.com/table.csv?s=^GSPC" & "&g=d&ignore=.csv"

With Worksheets("FTSE100RAW")
With .QueryTables.Add(Connection:="TEXT;" & URL, Destination:=.Range("A1"))
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh BackgroundQuery:=False
End With
.QueryTables(1).Delete
End With



End Sub


This runs in the workbook VBA page and as noted runs for 5 different indexes whereby I simply change the s=^ to change the index name.

After searching for hours across the internet ,I cannot find a code that automates the refresh in the background as you would with a dynamic web query using the above URL. I know how to do this within Excel just using the URL ,however this doesn't work here as there are multiple pages to be imported, thus VBA is needed to add the string dimension.

I would like the workbook to update at four times in the day, or every 30 mins either is preferable.

Can anyone please help me, I have been searching for a while and have only found code that related to creating stock inoput tools within a module for individual stocks with specified date ranges.

Thank you in advance

Kate
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top