Solved

how to read rtf file in webBrowser control?

Posted on 2002-07-19
7
694 Views
Last Modified: 2010-08-05
I've got a small app (both Access 2000 and VB6) that uses a web Browser control to navigate to a variety of sites.  I then parse the table info or text from the html and populate an Access table.

My problem is that one site that I need ends up delivering an rtf file.  My web Browser control loads the rtf file ok, but I can't seem to find the proper syntax, object properties, methods, etc. to then read the text.

Optionally, I could load the file to a RichTextBox control, but I can't seem to make the .LoadFile method of the RichTextBox control find the file on the internet site.


Any suggestions?

note: I've already tried "webBrowser.document.documentElement.innerHtml" or innerText or just "webBrowser.document.body.innerText" and gotten the error message:
"Object doesn't support this property or method."

It seems that once the rtf file is loaded, all of the normal webBrowser.document properties and methods are invalid.

0
Comment
Question by:PatOBrien
  • 3
  • 3
7 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7165801
To some extents, yes. i don't know if there is a "DOM" for rtf file format.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7165911
Well, as long as i can see, we could manage it like a word document, could you do a check?
(we have to use a better way to know which type of doc is but for testing, this would be enougth, wb1 is webbrowser control. We have to set a reference to microsoft word object library in the project)


Private Sub wb1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is wb1.Object) Then
    If Right$(wb1.Document.Name, 3) = "rtf" Then
        Dim wrtf As Word.Document
        Set wrtf = wb1.Document
       
    End If
End If
End Sub

Do an inspection over wrtf var and see...
0
 
LVL 27

Accepted Solution

by:
Ark earned 150 total points
ID: 7166326
Hi

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nSize As Long, ByVal lpBuffer As String) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
       "URLDownloadToFileA" (ByVal pCaller As Long, _
       ByVal szURL As String, _
       ByVal szFileName As String, _
       ByVal dwReserved As Long, _
       ByVal lpfnCB As Long) As Long

Public Function URLToTextBox(ByVal sUrl As String, txt As TextBox) As Boolean
  Dim sTemp As String, sHTML As String
  sTemp = GetTempDir & "dummy.html"
  If Dir$(sTemp) <> "" Then Kill sTemp
  Call URLDownloadToFile(0&, sURL, sTemp, 0, 0)
  Open sTemp For Binary As #1
       sHTML = Space(LOF(1))
       Get #1, , sHTML
  Close #1
  Kill sTemp
  txt.Text = sHTML
End Function

Public Function URLToRTB(ByVal sUrl As String, rtb As RichTextBox) As Boolean
  Dim sTemp As String, sHTML As String
  sTemp = GetTempDir & "dummy.rtf"
  If Dir$(sTemp) <> "" Then Kill sTemp
  Call URLDownloadToFile(0&, sURL, sTemp, 0, 0)
  rtb.LoadFile sTemp, rtfRTF
  Kill sTemp
End Function

Private Function GetTempDir() As String
  Dim tmp As String
  tmp = Space$(256)
  Call GetTempPath(Len(tmp), tmp)
  GetTempDir = TrimNull(tmp)
End Function

Private Function TrimNull(item As String)
  Dim pos As Integer
  pos = InStr(item, Chr$(0))
  If pos Then
     TrimNull = Left$(item, pos - 1)
  Else
     TrimNull = item
  End If
End Function


0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 5

Author Comment

by:PatOBrien
ID: 7169769
Richie,

It appears that it can (does) come in as Word Document.

What's next?


Ark,

I'll be trying your functions today.... will let you know what I find.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7169933
RTF could be read  to some extents as a Word Document
Better use Ark's code.
Cheers
0
 
LVL 5

Author Comment

by:PatOBrien
ID: 7170460
.... help me go in the right direction.

I added some "On Error" statements and set the function values.

Thanks.
0
 
LVL 5

Author Comment

by:PatOBrien
ID: 7175707
I meant that it "...helped me go in the right direction.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question