Code:
dim url As String
Dim xmlhttp As Object
Dim st As Integer
Dim Content As String
Dim searchString As String
Dim position As Long, exchange as string
url="MMM"
exchange="NYSE"
url = "https://www.google.com/finance/quote/" & UCase(symbol) & ":" & exchange
Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
xmlhttp.Open "GET", url, False
xmlhttp.Send
st = xmlhttp.Status ' Capture the HTTP status code
If st = 200 Then
Content = xmlhttp.responseText
searchString = "YMlKec fxKbKc"
position = InStr(Content, searchString) + Len(searchString) + 1
If position > 14 And position <= Len(Content) Then
FetchNumericValue = Trim(mid(Content, position + 1, 10))
FetchNumericValue = Trim(Left(FetchNumericValue, InStr(FetchNumericValue, "$") - 2))
FetchNumericValue = Trim(FetchNumericValue)
msgbox(FetchNumericValue )
End If
Else
MsgBox (st & " - " & xmlhttp.StatusText)
End If
Set xmlhttp = Nothing
i have been using the above code to extract from https://www.google.com/finance/quote/ the current price of stocks . the code runs nicely and fast with no issues, Some days nevertheless it does not work and points to an error "Access Denied" , on xmlhttp.Send
Why would it work some days and not other?
I would prefer not the option to navigate method as it takes way more time to read the data.
I appreciate your help