Results 1 to 9 of 9

Thread: WebBrowser Object

  1. #1
    Guest

    Thumbs up

    Hi all,

    I'm trying to set the content of the clipboard to be the words selected within the WebBrowser object. I've tried SendKeys "^C" but it didn't work. Anybody knows how to do this?

    What I want to do is for user to highlight words within the WebBrowser object by drag-selecting with the mouse and then click a "Find" button. Therefore I need to capture the words which is highlighted by user which is supposed to be stored in the clipboard.

    Is there any other way to do it besides SendKeys "^C" ?

    If sendkeys is the only way to capture the highlighted words, what is the proper way to code it?

    Any help is very appreciated.

    Rgds,
    David.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I had no problems using SendKeys. This is the code I used to try it out:
    Code:
    Private Sub Command1_Click()
        WebBrowser1.SetFocus
        SendKeys "^c", True
        MsgBox Clipboard.GetText
    End Sub
    The important thing is to set focus to the WebBrowser control before using SendKeys.

    Good luck!

  3. #3
    Guest

    Thanks a lot

    I typed ^C instead of ^c, no wonder it didn't work..
    thanks a lot for your help dude..

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Actually it doesn't matter if you type ^c or ^C.

  5. #5
    Guest
    And to search in the Webbrowser:

    Code:
    Private Sub Command1_Click()
        WebBrowser1.SetFocus
        SendKeys "^f", True 
        SendKeys "SearchText", True 
        SendKeys "~", True
    End Sub

  6. #6
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Please, don't use the SendKeys method. Remember, when you use the Webbrowser object, you have access to the Document object. If all you need to do is copy the highlighted text to the clipboard, just do the following:

    Code:
    Private Sub command1_click()
    
    Dim rng As Object
    
    Set rng = Webbrowser1.Document.selection.createRange()
    Clipboard.SetText rng.Text
    
    Set rng=Nothing
    end sub
    Hope this helps.

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Matthew Gates
    And to search in the Webbrowser:

    Code:
    Private Sub Command1_Click()
        WebBrowser1.SetFocus
        SendKeys "^f", True 
        SendKeys "SearchText", True 
        SendKeys "~", True
    End Sub
    Hmmm... yeah I posted that exact code in a previous post

    BTW reeset, do you have any documentation or help files on the web browser object, and in that case where can I get it.


  8. #8
    Guest
    That is the code you gave Joacim, sorry for not saying, "this code is from Joacim", wasn't even thinking about it.

    Well, it's Joacim's code. Thanks Joacim, it'll come in handy to me as well .

    Credit is given where it's needed.

  9. #9
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Joacim:

    Actually, the selection and createText are objects associated with IE's Document Object. For information on that, just go to Microsoft and look through their knowledge base on the HTML objects available to IE. Whenever I program with the Webbrowser control, I generally try to think of it just as the parent object, and then interact with it accordingly.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width