How to Bold Only Part of a Text String in Word Using VBA
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.

- 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.
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.
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.
Open your VBA Editor and ensure you have properly declared your Word Document object (e.g., wdDoc) to manipulate the target document's content.
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.
Use the InsertAfter method to add your specific label string into the document, for example: wdDoc.Content.InsertAfter "Severity: ".
Immediately after inserting the label, capture the new end position using endPosition = wdDoc.Content.End - 1.
Use the InsertAfter method again to insert the unformatted value associated with the label, such as wdDoc.Content.InsertAfter "Moderate".
Target the isolated label by applying the bold property to the exact recorded positions: wdDoc.Range(startPosition, endPosition).Font.Bold = True.

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. Download and Install: Visit the official WPS Office website to download the lightweight installer and complete the setup on your device.
- 2. Open Your Document: Launch WPS Writer and seamlessly open your existing .docx files without losing any formatting or layout settings.
- 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.

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.




