How to enable FPHTML Objects in VBA 7.1?
So clicking on the <tr> wasn't what you were looking for after all .... Iterating through the anchors was.
I was looking for the <tr> but not the anchors. To my surprise, the 'click' method worked for <tr> as well!
So, I have a table which displays all the row names as shown below. I need to extract the text marked as bold for specific rows. What's the best way to do this?
1st Row -> Cash from Operating Activity (Operating Activity)
2nd -> Operating profit (Operating profit)
3rd -> Working Capital Changes (Working Capital)
4th -> Taxes paid (Taxes Paid)
5h -> Cash from Investing Activity
6th -> Fixed Assets Purchased (Fixed Assets)
7th -> Fixed Assets Sold
8th -> Cash from Financing Activity
9th -> Net Cash Flow
So it looks like you're using the code that clicks the link. If you simply want check whether the link was found and clicked, you can use a Boolean variable to keep track of the status...Code
Dim HTMLLink As MSHTML.HTMLAnchorElement Dim bClicked As Boolean bClicked = False For Each HTMLLink In HTMLDoc.getElementsByTagName("a") If HTMLLink.innerText = "Cash Flow" Then HTMLLink.Click bClicked = True Exit For End If Next HTMLLink If bClicked Then MsgBox "Link found and clicked...", vbInformation Else MsgBox "Link not found...", vbInformation End If
Perfect! This is exactly what I'm looking for. Thank you so much.
Here's an example that loops through each link, checks for the text "Cash Flow", and then clicks the link...Code
But this simply brings you to the table located at the bottom of the same page. If you want to access the information in that table, you can loop through each table on the page, and check for the text "Cash from Operating Activity" from the second row...Code
Actually, instead of accessing the information from within this loop, you can exit it first, and then do so...Code
Dim HTMLTable As MSHTML.HTMLTable For Each HTMLTable In HTMLDoc.getElementsByTagName("table") If HTMLTable.getElementsByTagName("tr")(1).Cells(0).innerText = "Cash from Operating Activity" Then Exit For End If Next HTMLTable If Not HTMLTable Is Nothing Then 'Do stuff Else MsgBox "The Cash Flow table wasn't found.", vbInformation End If
Hope this helps!
Why not iterate over all the tags in the DOM to get to the anchor that says cashflow then it's as simple as objCurrent.Click.
If its an anchor, then I'm sure what you suggested would have worked but here its a 'tr' element. Please have a look at the DOM Structure.
After the URL mentioned in the code below is opened, the macro should simulate a click function on the 'Cash Flow' table by clicking on the row ' Cash from Operating Activity', which adds pseudo element rows to the webpage.Code
Sub GetHTMLDocument() Dim IE As SHDocVw.InternetExplorer Dim HTMLDoc As MSHTML.HTMLDocument Set IE = New SHDocVw.InternetExplorerMedium IE.Visible = True Url = "https://www.screener.in/company/522650/" IE.Navigate Url ' Wait till the Internet Explorer has finished loading Do While IE.ReadyState <> READYSTATE_COMPLETE Loop ' Stores a reference to the HTML Document in that variable Set HTMLDoc = IE.Document If HTMLDoc.ReadyState = "complete" Then End If