RTF to DOCX

Local time
Today, 20:15
Joined
Aug 3, 2005
Messages
66
Hi, just looking for ideas if anyone is interested...

In Access 2013 I export certain form fields to a Word docx file which has predefined Bookmarks. This works perfectly well.

Like so:

Code:
'code for Dims and Strings etc
'code for defining path, docx name etc

'then this:

With myDoc
.Bookmarks("txt_myWordBookmark1").Range.InsertAfter Me.txt_myFormField
.Bookmarks("txt_myWordBookmark2").Range.InsertAfter Me.txt_myOtherField
End With

'other code

The above works well as long as the text fields are Plain Text.

The Form(&fields) is based on a Table.

In the above example, the field txt_myFormField is a 'Long Text' (old Memo) field type.

In the table's design, the field's 'Text Format' property is set to 'Rich Text'.

Therefor, on the form, I can use text formatting features such as Bold, Underline and specifically BULLET LISTS.

Here is an example of when the field is filled in:

---------------------------
Heading in bold:

  • Item 1
  • Item 2
  • Item 3

The end.
----------------------------

When this Rich Text field is "exported" to Word as in my code above, the text placed at the Word doc's Bookmark, is in PLAIN TEXT, and with HTML tags, like so: Note that it is not in HTML format, but normal plain text including the tags:

----------------------------
<div>Heading in bold:</div>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
etc.
----------------------------

To resolve this I was thinking something in the line of the following, but I'm not sure what VBA would be efective in converting html tags to Word readable format:

Code:
.Bookmarks("txt_myWordBookmark1").Range.InsertAfter....
' then somehow Format/Convert...
...Me.txt_myFormField...
'to Word readable Rich Text

It is important that Word doc remains in docx format for further manual editing.

Any ideas are welcome. Please.

Thanks.
 
We needed to recreate a report in Word and the report had a rich text field. The only way we found we could do this is output the RTF to a file and then insert it into the Word document. In our case we inserted it into a Word text box. In the follow code segment pprs!What is the recordset field with the rich text.

Code:
Dim apWord As Word.Application
Dim doc As Word.Document
Dim What As Word.Shape
Set apWord = CreateObject("Word.application")
Set doc = apWord.Documents.Add("Normal", False, 0)

Set What = doc.Shapes.AddTextbox(msoTextOrientationHorizontal, doc.PageSetup.LeftMargin, 200, 240, 0)
Dim sPath As String
sPath = CurrentProject.Path & "\Temp.html"
Open sPath For Output As 1
Print #1, "<HTML>" & pprs!What & "</HTML>"
Close #1
What.TextFrame.TextRange.InsertFile (sPath)

Note that you need to add the HTML tags on or Word won't see it as HTML..

While this gets the formatting ok as I recall the line space doesn't appear the same as it did it the report. I believe we encountered extra lines.

I'd like to know if anyone has found a way to do this without to output to a file. I guess this is basically what your question was.
 
Last edited:
Thanks for this. I will give it a try or see how I can incorporate it in my situatation. Will post back with results.
 

Users who are viewing this thread

Back
Top Bottom