logo
search
VBA & Macro Problems

How to Combine Word VBA Macros with Different Font Sizes

Maira MehtabMaira Mehtab Sep 21, 2026 869 views

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.
Before you start

Ensure you have enabled the Developer tab in your Word processor to access the VBA Editor and review your existing macro code.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) Editor.

2
Create a Parameterized Subroutine

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`.

3
Create the Calling Macros

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)`.

4
Save and Run

Save your module, close the VBA Editor, and run your newly consolidated macro from the Developer tab in the ribbon.

Why Use Double?: Using the 'Double' data type ensures the VBA macro can accurately process decimal values for font sizes, avoiding rounding errors that would occur with 'Integer'.
Advanced Document Automation

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. 1. Install WPS Office: Download and install WPS Office from the official website.
  2. 2. Open Your Document: Launch WPS Writer and open the document containing your macros.
  3. 3. Access the Developer Tab: Navigate to the Developer tab on the top ribbon and click on 'Macros' or 'Visual Basic'.
  4. 4. Run Your Code: Paste your parameterized macro code into the editor and execute it seamlessly.
Fully compatible with Microsoft Word documents and standard VBA macros.Lightweight architecture ensures scripts run smoothly without lag.Includes a built-in Visual Basic Editor accessible directly from the ribbon.Free to use for everyday document creation and formatting tasks.
microsoft office alternative - wps office

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.