VBA error 429 cant create object

ERC2

New Member
Joined
Sep 12, 2011
Messages
33
I am trying to write a macro that will open Edge, go to yahoo finance, get a few pieces of information about a couple of stocks but I get a 429 error. Here is the macro I wrote. What did I do wrong?
Sub GetStockInfo()

' Define variables
Dim Edge As Object
Dim URL As String
Dim StockList As Variant
Dim i As Long
Dim Price As String
Dim EPS As String
Dim PE As String

' Set the URL for Yahoo Finance
URL = "https://finance.yahoo.com/"

' Set the list of stocks to search for
StockList = Array("GOOGL", "PFE", "MMM", "GS")

' Create an instance of Microsoft Edge
Set Edge = CreateObject("Microsoft.Edge.Application")

' Make the browser visible
Edge.Visible = True

' Navigate to Yahoo Finance
Edge.Navigate URL

' Wait for the page to load
Do While Edge.Busy Or Edge.readyState < 4
DoEvents
Loop

' Loop through the list of stocks
For i = 0 To UBound(StockList)
' Search for the stock symbol
Edge.Document.querySelector("input[aria-label='Search']").Value = StockList(i)
Edge.Document.querySelector("button[type='submit']").Click

' Wait for the search results to load
Do While Edge.Busy Or Edge.readyState < 4
DoEvents
Loop

' Extract the price, EPS, and P/E ratio
Price = Edge.Document.querySelector("span[data-reactid='50']").innerText
EPS = Edge.Document.querySelector("td[data-test='EPS_RATIO-value']").innerText
PE = Edge.Document.querySelector("td[data-test='PE_RATIO-value']").innerText

' Display the results in a message box
MsgBox StockList(i) & vbCrLf & "Price: " & Price & vbCrLf & "EPS: " & EPS & vbCrLf & "P/E Ratio: " & PE
Next i

' Quit Microsoft Edge
Edge.Quit
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
VBA does not have a built-in API for Edge, the way it does for IE. Did you just take code for IE and try to change it to Edge?
 
Upvote 0
It should work if you have IE installed on the machine. Windows used to come with it, so it's probably installed if you haven't removed it. It's no longer supported by Microsoft, but the API should still work. They are pushing everyone to Edge but didn't provide a VBA API for it. I don't know if they ever will. I suspect that they will also be pushing from VBA to Office Script over the long run.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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