![]() |
WebBrowser |
Post Reply
|
| Author | |
SteveStraley
Groupie
Joined: 25 November 2005 Status: Offline Points: 46 |
Post Options
Thanks(0)
Quote Reply
Topic: WebBrowserPosted: 20 May 2011 at 8:20pm |
|
Hi,
Does anyone know how, within the AxWebBrowser control, to capture a selected section of text displayed within the control? Thanks, Steve |
|
![]() |
|
jpcoffeyXXX
Groupie
Joined: 16 August 2005 Location: United States Status: Offline Points: 31 |
Post Options
Thanks(0)
Quote Reply
Posted: 19 June 2012 at 3:10pm |
|
Steve, the easy answer is,
Private Function RetrieveFrameSelectedTextEasy(wb As WebBrowser) As String
Dim oDoc As HTMLDocument, tr As IHTMLTxtRange
Set oDoc = wb.Document
If LCase$(oDoc.selection.Type) = "text" Then
Set tr = oDoc.selection.createRange
RetrieveFrameSelectedText = tr.Text
Set tr = Nothing
End If
Set oDoc = Nothing
End FunctionHowever, in many cases, there are several iFrames on the page and you do not know which iFrame may have selected text. In this case you would need to use the following, Private Function RetrieveFrameSelectedText(wb As WebBrowser) As String
Dim pContainer As olelib.IOleContainer
Dim pEnumerator As olelib.IEnumUnknown
Dim pUnk As olelib.IUnknown
Dim pBrowser As shdocvw.IWebBrowser2
'======================================
Dim oDoc As HTMLDocument
Dim tr As IHTMLTxtRange
RetrieveFrameSelectedText = vbNullString
Set pContainer = wb.Document
' Get an enumerator for the frames
If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then
Set pContainer = Nothing
' Enumerate all the frames
Do While pEnumerator.Next(1, pUnk) = 0
On Error Resume Next 'JPC - Edanmo's error handler
' Clear errors
Err.Clear
' Get the IWebBrowser2 interface
Set pBrowser = pUnk
If Err.Number = 0 Then
On Error GoTo 0
'Debug.Print "Private Sub EnumFrames Frame URL: " & pBrowser.LocationURL
Set oDoc = pBrowser.Document
If LCase$(oDoc.selection.Type) = "text" Then
Set tr = oDoc.selection.createRange
RetrieveFrameSelectedText = tr.Text
Set tr = Nothing
'Don't look for anymore selected text
Exit Do
End If
End If
Loop
Set oDoc = Nothing
Set pEnumerator = Nothing
End If
End Function |
|
![]() |
|
McKloony
Senior Member
Joined: 09 January 2007 Location: Germany Status: Offline Points: 340 |
Post Options
Thanks(0)
Quote Reply
Posted: 17 July 2012 at 5:14am |
|
Is it also possible so save the content of a Webbrowser control als MHT or HTML File?
|
|
|
Product: Xtreme SuitePro (ActiveX) 16.2.5
Platform: XP / Windows 7 Language: Visual Basic 6.0 SP6 |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |