Fix Word DOCVARIABLE Displaying RTF or HTML Tags as Plain Text in Word VBA
Question details
The user needs to populate a Word DOCVARIABLE or content control with rich text from Microsoft Access without displaying raw RTF or HTML markup.

- Product
- Microsoft Word VBA and Microsoft Access
- Device & OS
- not provided
- Scenario
- A Word document uses VBA to receive a value from Microsoft Access, and the value is assigned to a DOCVARIABLE and a content control's FormattedText property.
- Observed behavior
- The DOCVARIABLE and content control display the RTF or HTML control words as plain text instead of applying the intended formatting.
Check whether the Microsoft Access field contains raw HTML or RTF markup or already formatted rich text, and note the title or type of the target content control before editing the VBA code.
Convert HTML or RTF Markup to Word-Formatted Content Before Inserting
Use this when the Access field value contains HTML or RTF control words and the goal is to display formatted text in Word.
A Word DOCVARIABLE stores a string as plain text and does not interpret HTML or RTF control words. Assigning the same raw string to the FormattedText property also fails because FormattedText expects a formatted Word Range, not markup.
Convert the source content to a Word-formatted range first. Once the markup is rendered as Word formatting, assign that range to the content control or use the resulting text only for display.
Press Alt+F11 to open the Microsoft Visual Basic for Applications editor and locate the code that assigns the Access field value.
In the VBA code, use Documents.Add to create a temporary document, then import the HTML or RTF source through an HTML-capable or RTF-capable action such as opening the source file or inserting the file into the temporary document.
After Word renders the imported markup, select or store the resulting Range object instead of the original raw Access string.
Use the content control's Range.FormattedText property with the converted Word Range, for example: ActiveDocument.SelectContentControlsByTitle("Named").Item(1).Range.FormattedText = ConvertedRange.
Close the temporary document without saving after the formatted content has been assigned, so the main document contains only the intended rich text.

Use a Titled Rich-Text Content Control and Assign a Formatted Word Range
Use this when the source is already a Word Range or when you can supply formatted Word content instead of raw markup.
WPS Office Writer: A Free Alternative for Word Rich-Text Tasks
This DOCVARIABLE markup issue belongs to Microsoft Word and Microsoft Access automation. WPS Office does not directly patch Word VBA, but it offers a free, lightweight Office alternative with familiar formatting tools and strong Microsoft Word format compatibility for everyday rich-text work.
- 1. Download WPS Office Free: Go to the WPS Office download page and install WPS Office on your device.
- 2. Open your Word document in WPS Writer: Launch WPS Writer and open the .docx, .doc, or .rtf file that contains the document content you need to format.
- 3. Use built-in formatting and content controls: Use the Home and Insert ribbon tools to apply formatting or insert rich-text content without relying on raw HTML or RTF markup in a DOCVARIABLE.

Frequently Asked Questions
Why does a Word DOCVARIABLE show HTML or RTF tags as plain text?
A DOCVARIABLE field stores the assigned string as plain text and does not interpret HTML or RTF control words. You must convert the markup to Word-formatted content before inserting it or use a rich-text content control with a formatted Word range.
Can I assign an HTML string directly to the FormattedText property?
No. The FormattedText property expects a formatted Word Range, not raw HTML or RTF text. Assigning a raw string will display the markup as plain text instead of removing or rendering it.
How do I convert HTML to Word formatting in Word VBA?
Import the HTML through Word's HTML-capable import path, for example by opening the .htm file or inserting the file into a temporary document, then select or store the resulting Range and assign that Range to the rich-text content control.
What is the difference between a DOCVARIABLE and a rich-text content control?
A DOCVARIABLE stores a string and displays a field result as text, while a rich-text content control can hold and display formatted Word content. For rich formatting, use the rich-text content control and assign a formatted Word Range.
Does Word VBA remove HTML tags automatically when inserting Access data?
No. Word VBA does not automatically strip or interpret HTML or RTF tags from a raw Access string. The source text must be converted to Word-formatted content first, or the tags will appear as plain text.




