PDA

View Full Version : Solved: Search for text in IE



chacanger
02-12-2011, 03:02 PM
Hi

I have recently been trying to automate a few processes with IE using Excel VBA. I wondered how can you search for a specific word in a website, I know how to do the rest of the automation but for example if I want to search for a piece of text on Google that says VBAX Original Green and tells me in a MsgBox if it has found it or not.

Here is my test code...
References used: Microsoft Internet Controls Enabled

Sub Search_Text()

Dim ie As InternetExplorer
Set ie = New InternetExplorer

' hide the mouse

ie.Navigate "http://www.google.co.uk/"
Do Until ie.ReadyState = READYSTATE_COMPLETE

Loop

ie.Visible = True


'||||||||THIS IS WERE THE TEXT SHOULD BE SEARCHED|||||||||


MsgBox "The text has been found!", vbOKOnly, "Message"
Else
MsgBox "No text found!", vbOKOnly, "Message"
End If

End Sub

Thanks

mdmackillop
02-13-2011, 10:55 AM
Does this help?
http://www.vbaexpress.com/kb/getarticle.php?kb_id=295

chacanger
02-13-2011, 01:29 PM
Does this help?
http://www.vbaexpress.com/kb/getarticle.php?kb_id=295

Thanks for the reply

I was trying to search how to obtain specific text without having to copy all the page to Excel, it would also need to search a certain criteria in the code with any Input Boxes, I've seen it be done before but I can't seem to find the example anywhere.:think:

Shred Dude
02-13-2011, 09:21 PM
The text you're seeking will be withing the Documnet object of the browser.

One method is to use various string searching techniques using INSTR, MID, LEFT, etc.

for example in your code:

startLoc=Instr(1,ie.document.body.innerhtml,"VBAX Original Green")


...will tell you the location that text first appears in the document. Depending on your objectives, string stripping can be very effective if you're just after one unique piece on a page.

HTH

chacanger
02-14-2011, 12:45 PM
The text you're seeking will be withing the Documnet object of the browser.

One method is to use various string searching techniques using INSTR, MID, LEFT, etc.

for example in your code:

startLoc=Instr(1,ie.document.body.innerhtml,"VBAX Original Green")


...will tell you the location that text first appears in the document. Depending on your objectives, string stripping can be very effective if you're just after one unique piece on a page.

HTH

That's It! :bow:

That's exactly what I was looking for, thank you very much for you help, this will save me copying all the sheet into Excel.