logo
search
VBA & Macro Problems

How to Bold Only Part of a Text String in Word Using VBA

Muhammad TalhaMuhammad Talha Oct 8, 2026 869 views

Question details

The user needs to apply bold formatting to a specific substring (such as a label) within a larger text string when automating data insertion into Word using VBA.

How to Bold Only Part of a Text String in Word Using VBA
Product
Word, Excel
Device & OS
not provided
Scenario
Copying data from Excel and inserting it into a Word document via VBA, where a label like 'Severity:' requires bold styling but its corresponding value must remain unformatted.
Observed behavior
Applying the bold font property to the entire inserted string results in both the label and the value becoming bold, which is incorrect.
Before you start

Ensure that the Developer tab is enabled in your Office application and that you have basic familiarity with the VBA Editor and Object Model for manipulating Word document ranges.

Solution 1Recommended

Insert Text Separately and Target the Specific Range

By capturing the start and end character positions of the label as it is inserted, you can target the bold formatting command exclusively to that specific range.

When VBA inserts a string of text, treating it as a single block will apply identical formatting across all characters. To format only a portion of the text, you must split the insertion process. Record the document's character index before inserting the label, and again immediately after. This creates an exact boundary that allows the Range object to bold only the label, leaving the subsequently inserted value completely unformatted.

1
Define Document and Range Objects

Open your VBA Editor and ensure you have properly declared your Word Document object (e.g., wdDoc) to manipulate the target document's content.

2
Record the Start Position

Before inserting your label, capture the current end position of the document's content by assigning it to a variable, such as startPosition = wdDoc.Content.End - 1.

3
Insert the Label Text

Use the InsertAfter method to add your specific label string into the document, for example: wdDoc.Content.InsertAfter "Severity: ".

4
Record the End Position

Immediately after inserting the label, capture the new end position using endPosition = wdDoc.Content.End - 1.

5
Insert the Value Text

Use the InsertAfter method again to insert the unformatted value associated with the label, such as wdDoc.Content.InsertAfter "Moderate".

6
Apply Bold Formatting to the Defined Range

Target the isolated label by applying the bold property to the exact recorded positions: wdDoc.Range(startPosition, endPosition).Font.Bold = True.

Insert Text Separately and Target the Specific Range
Dynamic Formatting Complete: This method ensures that no matter how long the variable value is, the bold formatting will strictly apply only to the predefined label.
Efficient Document Automation with WPS Office

Automate and Format Documents Seamlessly in WPS Office

WPS Office provides exceptional compatibility with standard document formats and supports advanced document formatting workflows. Its familiar interface allows you to manage text styles efficiently and automate repetitive tasks with ease.

  1. 1. Download and Install: Visit the official WPS Office website to download the lightweight installer and complete the setup on your device.
  2. 2. Open Your Document: Launch WPS Writer and seamlessly open your existing .docx files without losing any formatting or layout settings.
  3. 3. Access Developer Tools: Navigate to the Developer tab on the ribbon to access macros, form controls, and advanced formatting options to customize your workflow.
Highly compatible with Microsoft Word (.docx) and Excel (.xlsx) formats.Supports advanced document formatting, styles, and automated workflows in professional editions.Lightweight and fast, ensuring smooth and rapid document processing.Familiar, intuitive user interface that requires zero learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the entire paragraph become bold when I apply formatting via VBA?

This occurs if your VBA code applies the .Font.Bold = True property to an entire paragraph object or a general selection range, rather than isolating specific start and end character positions for the exact word or label.

Can I use the Find and Replace method in VBA to bold a specific word?

Yes, you can use the Find object in VBA to search the document for a specific label like "Severity:". Once found, you can set the Replacement.Font.Bold property to True and execute the replacement to format the text after it has already been inserted.

Does this VBA range method work when controlling Word from Excel?

Yes, as long as you have properly initialized the Word.Application and Word.Document objects within your Excel VBA script, you can control Word ranges and apply formatting properties seamlessly across applications.