|
-
Oct 18th, 2013, 11:34 AM
#22
New Member
Re: [RESOLVED] Highlighting Text in a Web Browser Control
Thank you for your suggestion, jmsrickland.
I tried your idea to clone WB as
Set doc = WebBrowser1.Document
sSourceHtml = doc.body.innerHTML
WebBrowser2.Document.write sSourceHtml
but unfortunately second WB losts the layout, formattings and picture sizes.
I also tried iPrank suggestion to use execCommand. I cloned WB as
Set doc = WebBrowser1.Document
Set tr = doc.body.createTextRange
DoEvents
l = tr.execCommand("COPY", False, Null) ' copy to clipboard '
Set doc2 = WebBrowser2.Document
Set tr2 = doc2.body.createTextRange
l = tr2.execCommand("PASTE", False, Null) 'paste from clipboard
but second WB also losts the layout, formattings and picture sizes.
I post the both codes below.
Private Sub cmdClone1_Click()
Dim doc As HTMLDocument
Dim tr As IHTMLTxtRange
Dim doc2 As HTMLDocument
Dim tr2 As IHTMLTxtRange
Dim sSourceHtml As String
Dim l As Long
'WebBrowser1.Navigate ("www.Microsoft.com") 'was already completed on previous step
WebBrowser2.Silent = True
WebBrowser2.Navigate ("about:blank")
Set doc = WebBrowser1.Document
DoEvents
sSourceHtml = doc.body.innerHTML
WebBrowser2.Document.write sSourceHtml
DoEvents
End Sub
Private Sub cmdClone2_Click()
Dim doc As HTMLDocument
Dim tr As IHTMLTxtRange
Dim doc2 As HTMLDocument
Dim tr2 As IHTMLTxtRange
Dim sSourceHtml As String
Dim l As Long
'WebBrowser1.Navigate ("www.Microsoft.com") 'was already completed on previous step
WebBrowser2.Silent = True
WebBrowser2.Navigate ("about:blank")
Set doc = WebBrowser1.Document
Set tr = doc.body.createTextRange
DoEvents
l = tr.execCommand("COPY", False, Null) ' copy to clipboard '
Set doc2 = WebBrowser2.Document
Set tr2 = doc2.body.createTextRange
l = tr2.execCommand("PASTE", False, Null) 'paste from clipboard
End Sub
****ANY SUGGESTIONS?****
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|