Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


WebBrowser Control VB

Posted on 2011-05-12
Medium Priority
Last Modified: 2012-05-11

Whats the easiest way to highlight all the text in a WebBrowser control and put it into a string variable?

I was going to program select all on the webbrowser handle.. than copy.. than take the contents of the clipboard.. but I imagine theres an easier way
Question by:bail3yz
  • 3
LVL 20

Accepted Solution

hes earned 2000 total points
ID: 35756434
Web1.Document.body.innerHTML will give you the page , you can then parse the text returned in that to fine the text you wanted.

Dim blnComp As Boolean
Dim strHtml As String
Dim sPos As Long
Dim ePos As Long
Dim strYourText as String

'Navigate to the site
Web1.Navigate2 TargetUrl
      blnComp = False
      Do Until blnComp = True And Web1.Busy = False
'find the start and end points you are looking for
      sPos = InStr(strHtml, "Something")
      ePos = InStr(sPos, strHtml, "SomethingElse")
strYourText = Mid(strHtml, sPos, (ePos - sPos) - 1)

Private Sub Web1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
   blnComp = True
End Sub

Author Comment

ID: 35757909
Web1.Document.body.innerHTML does not give me the text I want.. I tried that already :(

Author Comment

ID: 35757956
just to clarify the text i want shows up as a variable in innerhtml

Author Comment

ID: 35758547
Ah my mistake.. your method did work.. I was just doing it too soon

I was doing it as soon as the page download was complete, however apparently the variables werent filled until shortly after.. strange.. but whatever


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question