Formatting Issues

Fix Word DOCVARIABLE Displaying RTF or HTML Tags as Plain Text in Word VBA

Elise WilliamsElise Williams Nov 13, 2026 870 views

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.

How to Fix Word DOCVARIABLE Displaying RTF or HTML Tags as Plain Text in Word VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor in Word

Press Alt+F11 to open the Microsoft Visual Basic for Applications editor and locate the code that assigns the Access field value.

2
Create a temporary Word document for conversion

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.

3
Capture the converted Word range

After Word renders the imported markup, select or store the resulting Range object instead of the original raw Access string.

4
Assign the formatted range to the content control

Use the content control's Range.FormattedText property with the converted Word Range, for example: ActiveDocument.SelectContentControlsByTitle("Named").Item(1).Range.FormattedText = ConvertedRange.

5
Remove the temporary document

Close the temporary document without saving after the formatted content has been assigned, so the main document contains only the intended rich text.

Convert HTML or RTF Markup to Word-Formatted Content Before Inserting
Plain-text fields remain plain text: If you continue to assign a string directly to a DOCVARIABLE field, Word will always show that string as plain text unless the field result is replaced by separately formatted content.
Free Microsoft Office alternative

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. 1. Download WPS Office Free: Go to the WPS Office download page and install WPS Office on your device.
  2. 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. 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.
Opens, edits, and saves Word .docx, .doc, and .rtf files with high compatibility.Familiar ribbon interface makes switching from Word and Access-based document automation easier.Built-in text and rich-text content tools reduce the need to debug DOCVARIABLE and VBA markup conversion.Free and lightweight Office suite for Windows, macOS, Android, and iOS.Supports seamless migration of existing Word documents without requiring paid Microsoft Office licenses.
QA img-9

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.