Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get formatted text from embedded browser?

Status
Not open for further replies.

TimMyth

Technical User
Feb 11, 2003
4
US
I have embedded a webbrowser into my Excel XP document, and have created the appropriate Home, back, forward, etc buttons to control it. It works nicely. However, I am having problems getting the formated text from the web page into my Excel sheet. I would like for it to automatically paste the text onto the Excel sheet in the same format used on the web page. The page has several tables, and text color is important.

I tried using worksheets("sheet1").range("a1") = WebBrowser.Document.documentelement.outertext, but that only puts the entire web page text into cell A1. Using range("a1:z50") puts the entire web page text into cells A1:Z50.

I have also tried using a RichTextBox, but the entire page doesn't display in the box, instead only the first portion of the page appears. The other problem with the RichTextBox is that the text loses its color, which leads me to beleive that .documentelement.outertext will only provide the text and not the formatting.

I could just require the user to physically copy and paste the page to sheet, but thats not a very elegant solution.

 

I believe ...
[tt]
WB.Document.body.innerText
[/tt]
will return the body of the document (text only, no formatting)

Good Luck

 
I've got the same problem. I have a embedded webbrowser control in a userform, and I need to assign the text value in the loaded webpage to a variable to process, but I keep getting "Run time error '91' Object variable or With block not set" errors...

Here's the code I'm using:
=========================================
Private Sub BROWSERS_LOGON_NavigateComplete2(ByVal pDisp As Object, URL As Variant)


Set htDoc = BROWSERS_LOGON.Document
dt = htDoc.body.InnerText
'I've also tried: Set dt = htDoc.body.InnerText
MsgBox (dt)


End Sub
=========================================

Any ideas on how to get this to work???
------------------------------------
[yinyang] 18 years of programming, and still learning every day! [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top