How to Extract Text Between Parentheses in a Word Template Filename
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.

- 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.
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.
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.
Launch your Word document and press the 'Alt + F11' keys simultaneously to open the Microsoft Visual Basic for Applications window.
In the top menu, click 'Insert' and select 'Module' to create a blank canvas for your script.
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)
Press 'F5' or click the 'Run' button. The variable 'fileName' will now return the exact string located between the parentheses.

Extract the Text Using Windows PowerShell
If VBA is strictly prohibited, you can use Windows PowerShell to extract the text from the filename before importing it into Word.
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.

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.




