How to Change Font in All Word Text Boxes Using a VBA Macro
Question details
The user needs to apply a specific font to all text within a document, including the text located inside all text boxes, using a VBA macro.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Updating formatting across a large document where standard font changes do not automatically apply to nested shapes like text boxes.
- Observed behavior
- The goal is to prompt for a font name and automatically apply it universally across the main document text and all text box shapes without manually selecting each one.
Verify the exact spelling of the font name you intend to use, and ensure your document is saved as a macro-enabled file (.docm) before running the code.
Use a VBA Macro to Update Main Text and Text Boxes
Implement a VBA script that prompts for a font name and loops through all document shapes to apply the new font globally.
This macro first updates the main body of the document and then iterates through all shapes. If a shape is identified as a text box (msoTextBox), it applies the new font to the text inside it.
Open your Word document and press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) Editor.
In the VBA Editor, click on 'Insert' in the top menu bar, and then select 'Module' to open a blank code window.
Copy and paste the FontNameAll macro script into the module window. Ensure the code includes the InputBox prompt for the font name, sets ActiveDocument.Range.Font.Name, and loops through ActiveDocument.Shapes to modify TextFrame.TextRange.Font.Name for msoTextBox types.
Close the VBA Editor. Back in your document, press Alt + F8 to open the Macros dialog box. Select 'FontNameAll' from the list and click 'Run'.
When the prompt appears, type the exact name of your desired font (e.g., 'Arial' or 'Times New Roman') and click 'OK' to apply the changes.

Run Macros and Format Documents Seamlessly in WPS Writer
WPS Writer offers extensive compatibility with Microsoft Word documents, including support for VBA macros in specific professional versions. You can easily manage complex document formatting and automate repetitive tasks across all your files.
- 1. Open Your Document: Launch WPS Writer and open your macro-enabled document.
- 2. Access the Developer Tab: Navigate to the 'Developer' tab on the top ribbon to access advanced tools.
- 3. Open the Macros Manager: Click 'Macros' or press Alt+F8 to view and manage your document's VBA macros.
- 4. Execute the Macro: Select your text-box formatting macro from the list and click 'Run' to apply the font changes.

Frequently Asked Questions
Why didn't the font change after I ran the macro?
This typically happens if the font name was misspelled in the input prompt. Because the macro does not return an error for non-existent fonts, you should verify the exact font name in your font library and run the macro again.
Will this macro change text inside grouped shapes or tables?
This specific macro targets the main document range and standalone text boxes (msoTextBox). Text inside tables is naturally covered by the main document range, but text in grouped shapes may require modifying the VBA script to loop through grouped sub-items.
Can I undo the macro's changes if I make a mistake?
Yes, you can typically press Ctrl + Z immediately after running the macro to revert the font changes across the document and text boxes.




