Others

How to Extract Text Between Parentheses in a Word Template Filename

Camila MilosovichCamila Milosovich Nov 4, 2026 869 views

Question details

The user needs a method to extract specific text enclosed within parentheses from the filename of a Word template, ideally without relying on VBA macros.

How to Extract Text Between Parentheses in a Word Template Filename
Product
Microsoft Word
Device & OS
not provided
Scenario
Parsing and organizing template information where the actual document filename contains critical metadata inside parentheses (e.g., 'Text(0 period Cover 2021 06).dotx').
Observed behavior
Standard Word fields lack built-in worksheet-style formulas to parse strings dynamically, meaning the text cannot be extracted without VBA or an external script.
Before you start

Verify whether your organizational policies allow the execution of VBA macros, as this is the only built-in method Word offers for string parsing. If macros are restricted, prepare to use an external tool like Windows PowerShell.

Solution 1Recommended

Use a VBA Macro to Parse the Filename

Although a non-VBA approach is often preferred, VBA is the most direct way to automatically parse and extract text from a filename within Word.

Since Word does not feature an equivalent to Excel's MID or SEARCH formulas within its standard field codes, Visual Basic for Applications (VBA) remains the primary native solution for string manipulation.

1
Open the VBA Editor

Launch your Word document and press the 'Alt + F11' keys simultaneously to open the Microsoft Visual Basic for Applications window.

2
Insert a New Module

In the top menu, click 'Insert' and select 'Module' to create a blank canvas for your script.

3
Paste the Extraction Code

Input the following script to define your variables and extract the text: Dim templateName As String, fileName As String templateName = "Text(0 period Cover 2021 06).dotx" fileName = Mid(templateName, InStr(templateName, "(") + 1) fileName = Left(fileName, InStr(fileName, ")") - 1)

4
Run the Macro

Press 'F5' or click the 'Run' button. The variable 'fileName' will now return the exact string located between the parentheses.

Use a VBA Macro to Parse the Filename
Macro Security: Ensure that your macro security settings in the Trust Center allow the execution of scripts, otherwise the VBA code will be blocked from running.
Free Microsoft Office alternative

Try WPS Office for Seamless Word Processing

While extracting complex text strings from filenames often requires advanced scripts in standard word processors, WPS Office offers a highly compatible, lightweight, and free alternative to Microsoft Word. It supports all standard document formats natively, providing a familiar UI and seamless migration for your daily tasks.

Free to use with a familiar, easy-to-navigate interfaceFully compatible with Microsoft Word formats (.docx, .doc, .dotx)Lightweight software that installs quickly and runs smoothlySeamless migration from other office suites without formatting loss
microsoft office alternative - wps office

Frequently Asked Questions

Can I use Excel formulas in Word to parse text?

No, Word does not support Excel's native text-parsing formulas like MID, LEFT, or FIND directly within its standard document fields. You must either use VBA or perform the data extraction in Excel before importing the results into Word.

How does the VBA InStr function work?

The InStr function in VBA searches for a specific character or substring within a text string and returns its numerical starting position. In this scenario, it is used to precisely locate the opening and closing parentheses in the filename.

Is there a built-in Word Field code to extract part of a filename?

While Word provides a FILENAME field code to insert the full document name into the text, it does not possess built-in switches or nested capabilities to isolate or extract only a specific portion of that filename.