VBA & Macro Problems

How to Use a Word Macro to Parse Script Text and Apply Styles

Tauseeq MagsiTauseeq Magsi Nov 3, 2026 869 views

Question details

The user needs to reformat a long script document by distinguishing performer names (before a colon) from dialog text (after a colon) and apply specific styles, as well as extract this data into a structured Excel format.

How to Parse Script Text and Apply Styles Using a Word Macro
Product
Word
Device & OS
not provided
Scenario
Formatting a script or transcript where performers and dialogs need distinct styling and data extraction.
Observed behavior
The script lacks structured formatting, making it difficult to differentiate performer names from dialogs visually or extract them efficiently.
Before you start

Create a backup copy of your document before running any macros, as bulk VBA replacements usually cannot be safely undone using the standard Undo feature.

Solution 1Recommended

Use a VBA Macro to Format Performer Names

Apply a specific style to text preceding a colon (the performer's name) using wildcard Find and Replace within a VBA macro.

This macro utilizes Word's wildcard search capability to identify text at the start of a paragraph up to a colon, and automatically applies the 'Strong' style to distinguish performers from dialog.

1
Open the VBA Editor

Open your script document in Word and press ALT + F11 to launch the VBA Editor.

2
Insert a New Module

In the left-hand Project pane, right-click your document name, select 'Insert', and choose 'Module'.

3
Paste the Formatting Macro

Paste the following code into the module window: Sub FormatPerformers() Application.ScreenUpdating = False With ActiveDocument.Range .Style = wdStyleNormal .Font.Reset With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "[!^13]@:" .Replacement.Text = "^&" .Replacement.Style = wdStyleStrong .Forward = True .Format = True .Wrap = wdFindContinue .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End With Application.ScreenUpdating = True End Sub

4
Run the Macro

Press F5 or click the 'Run' button in the toolbar. The macro will process the entire document, applying the bold 'Strong' style to all performer names.

Use a VBA Macro to Format Performer Names
Wildcard Search Tip: The expression '[!^13]@:' looks for any sequence of characters that is not a paragraph break (^13) followed by a colon, ensuring only the name portion is targeted.
Use WPS Writer for Advanced Document Formatting

Format Scripts and Transcripts Efficiently in WPS Office

WPS Writer natively supports advanced Find and Replace with wildcards, allowing you to quickly format complex scripts without writing any VBA code. It also seamlessly integrates with WPS Spreadsheet for easy text-to-columns data extraction.

  1. 1. Open Your Script in WPS Writer: Launch WPS Office and open your script or transcript document.
  2. 2. Access Find and Replace: Press Ctrl + H to open the Find and Replace dialog box.
  3. 3. Enable Wildcards: Click 'Options' to expand the search settings and check the 'Use wildcards' box.
  4. 4. Set Formatting Rules: In the 'Find what' field, type '[!^13]@:'. Leave the 'Replace with' field blank, but click 'Format' > 'Style' to apply your preferred performer style.
  5. 5. Replace All: Click 'Replace All' to instantly style the performer names throughout the entire script.
Fully compatible with Microsoft Word document formats (.doc, .docx)Robust Find and Replace utility featuring comprehensive wildcard supportSeamless copy-paste integration between WPS Writer and WPS SpreadsheetLightweight, fast, and completely free to use
microsoft office alternative - wps office

Frequently Asked Questions

Can I apply these styles without using a VBA macro?

Yes, you can manually use the built-in Find and Replace feature with wildcards enabled. Search for '[!^13]@:' (text ending with a colon) and apply your desired formatting via the Replace format options.

Why didn't the Text to Columns feature separate my script correctly in Excel?

This usually happens if the delimiter (such as a colon) is missing in some paragraphs or if a single dialog spans multiple paragraphs without the performer's name being repeated. You must group or prefix the text properly before exporting.

How do I handle dialogs that span multiple paragraphs?

You need to define a consistent paragraph marker or use a secondary macro to prefix the performer's name at the start of every continuing paragraph. Otherwise, standard extraction methods will treat the new paragraph as an unassigned line.

Are macros safe to run on my document?

Macros are safe if you wrote them or obtained them from a trusted source. Because macro actions cannot typically be undone, always test them on a duplicate copy of your document first.