VBA Web Query to Yahoo Finance

niras

New Member
Joined
Mar 3, 2010
Messages
3
I am trying to run a VBA Web Query to Yahoo Finance to get monthly stock price data. The error I get is : 'Run Time Error 1004' Unable to open <site> Cannot connect to the internet server.
I would greatly appreciate any help. My complete code is below.

Sub RunQuery(StSymbol As String)
'Dim ConnectStr As String
ConnectStr = "URL; http://finance.yahoo.com/q/hp?<wbr>s=" & StSymbol & "&a=" & BMonth & "&b=2" & "&c=" & BYear & "&d=" _
& EMonth & "&e=2&f=" & EYear & "&g=m"

Debug.Print ConnectStr
With ActiveSheet.QueryTables.Add(<wbr>Connection:=ConnectStr, Destination:=Range("$A$1"))
.Name = "StockPrices_" & StSymbol
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "20"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=True '(ERROR HERE)
End With
End Sub
 
Hi Martyloo,

Just in case you didn't solve this.

I think the error is with the space after URL; http

code should be:

Code:
[COLOR=#333333]ConnectStr = "URL[/COLOR][COLOR=#b22222];h[/COLOR][COLOR=#333333]ttp://finance.yahoo.com/q/hp?s= ... blah...blah[/COLOR]
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,216,031
Messages
6,128,422
Members
449,450
Latest member
gunars

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