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.
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
- 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
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