Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCopy all of the text from a WebBrowser control
DescriptionThis example shows how to copy all of the text from a WebBrowser control in Visual Basic 6.
Keywordscopy text, clipboard, WebBrowser, Ctrl-A, Ctrl-C
CategoriesTips and Tricks, Controls
 
Thanks to Marco Blume.

Use the keybd_event API function to send the application Ctrl-A to select all of the text and then Ctrl-C to copy the text to the clipboard. Then use the Clipboard object's GetText method to get the text.

 
' Grab all of the text in the WebBrowser control.
Private Sub Command1_Click()
    ' Clear the clipboard.
    Clipboard.Clear

    ' Set focus to the WebBrowser control.
    WebBrowser1.SetFocus

    ' Control-A.
    ' Press Control.
    keybd_event VK_CONTROL, 0, 0, 0
    DoEvents

    ' Press A.
    keybd_event VK_A, 1, 0, 0
    DoEvents

    ' Control-C.
    ' Press Control.
    keybd_event VK_CONTROL, 0, 0, 0
    DoEvents

    ' Press C.
    keybd_event VK_C, 1, 0, 0
    DoEvents

    ' Release Control.
    keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
    DoEvents

    ' Get the text from the clipboard.
    Text1.Text = Clipboard.GetText
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated