How to Combine Word VBA Macros with Different Font Sizes
Question details
The user wants to combine two nearly identical Word VBA macros that perform the same search and formatting tasks but apply different font sizes.
- Product
- Word
- Device & OS
- not provided
- Scenario
- Consolidating redundant VBA code procedures into a single, cleaner macro to apply varying font formats (10.5 and 13).
- Observed behavior
- Currently, the user is maintaining two separate procedures with duplicated logic because the font sizes are hardcoded differently in each.
Ensure you have enabled the Developer tab in your Word processor to access the VBA Editor and review your existing macro code.
Use a Parameterized VBA Procedure
Refactor the duplicate code into a single subroutine that accepts the font size as a parameter, then call it with the specific values.
Instead of duplicating your search and replace logic, you can define a 'Double' parameter in your subroutine. This allows you to pass specific decimal font sizes (like 10.5 and 13) dynamically when calling the macro.
Press Alt + F11 to open the Visual Basic for Applications (VBA) Editor.
Define a new sub that accepts a parameter by typing: `Sub ApplyFormat(fontSize As Double)`. Place your shared search and formatting logic inside, replacing the hardcoded font size with `Selection.Font.Size = fontSize`.
Create your main macros or a single control macro that triggers the parameterized subroutine. Use the Call statement, such as `Call ApplyFormat(10.5)` and `Call ApplyFormat(13)`.
Save your module, close the VBA Editor, and run your newly consolidated macro from the Developer tab in the ribbon.
Run Macros Efficiently with WPS Office
WPS Office provides excellent support for VBA macros and document automation. You can easily write, combine, and execute your parameterized scripts within WPS Writer's intuitive Developer environment.
- 1. Install WPS Office: Download and install WPS Office from the official website.
- 2. Open Your Document: Launch WPS Writer and open the document containing your macros.
- 3. Access the Developer Tab: Navigate to the Developer tab on the top ribbon and click on 'Macros' or 'Visual Basic'.
- 4. Run Your Code: Paste your parameterized macro code into the editor and execute it seamlessly.

Frequently Asked Questions
Why do I need to use a 'Double' parameter instead of 'Integer' for font sizes?
Font sizes frequently include decimal or half-point values, such as 10.5. The 'Double' data type handles precise decimal values in VBA, whereas an 'Integer' would round the number up or down, leading to incorrect formatting.
How do I call a macro with parameters in Word VBA?
You can call a parameterized macro by using the 'Call' keyword followed by the name of the subroutine and passing the required values in parentheses. For example: `Call MyFormattingMacro(13)`.
Can I pass multiple formatting options to a single VBA macro?
Yes, you can define multiple parameters in a single subroutine, separating them with commas. For instance, `Sub FormatText(fontSize As Double, isBold As Boolean)` allows you to pass both a font size and a true/false value for bolding.
How do I enable the Developer tab to edit VBA macros?
Go to File > Options > Customize Ribbon. In the right-hand pane, check the box next to 'Developer' and click OK to display the tab on your main interface.




