How to Use a Word Macro to Parse Script Text and Apply Styles
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.

- 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.
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.
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.
Open your script document in Word and press ALT + F11 to launch the VBA Editor.
In the left-hand Project pane, right-click your document name, select 'Insert', and choose 'Module'.
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
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.

Group Multi-Paragraph Dialog for Excel Extraction
Prefix multi-paragraph dialogs with the performer's name so each paragraph is properly attributed before exporting the script to Excel.
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. Open Your Script in WPS Writer: Launch WPS Office and open your script or transcript document.
- 2. Access Find and Replace: Press Ctrl + H to open the Find and Replace dialog box.
- 3. Enable Wildcards: Click 'Options' to expand the search settings and check the 'Use wildcards' box.
- 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. Replace All: Click 'Replace All' to instantly style the performer names throughout the entire script.

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.




