Using VBA to search for a specific Class Element in a website source code for a dynamic list of search terms

silverhaze

New Member
Joined
Apr 12, 2021
Messages
1
What I am trying to do, is to paste a term from a list into a search bar and then return a value into the spreadsheet depending on whether the search yields results or not. I would like the VBA code to cycle through the list of items automatically.

  • Search term from Column A1 - Output if class elemnt was found in Column B1
  • Search term from Column A2 - Output if class elemnt was found in Column B2
  • Search term from Column A+n - Output if class elemnt was found in Column B+n
My code as it looks below. What is missing is the instruction to automatically cycle through the list of search terms in column A:
Sub Browsetosite()

Dim IE As New SHDocVw.InternetExplorer
Dim htmldoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim classElement As Object

IE.Visible = True
IE.navigate "WEBSITE"

Do While IE.readyState <> READYSTATE_COMPLETE

Loop

Set htmldoc = IE.document
Set HTMLInput = htmldoc.getElementById("....")
Set HTMLButtons = htmldoc.getElementsByTagName("....")

HTMLInput.Value = Range("A1")

IE.document.getElementById("TEXT").Click

While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Application.Wait (Now + TimeValue("0:00:01"))

Set classElement = htmldoc.getElementsByClassName("...")(0)

If classElement Is Nothing Then

ActiveSheet.Range("B1").Value = "No result found"

Else
ActiveSheet.Range("B1").Value = "Requires checking"

End If

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,224,813
Messages
6,181,109
Members
453,021
Latest member
Justyna P

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