VBA & Macro Problems

How to Adjust Character Spacing Incrementally using Word VBA Macro

John WilsonJohn Wilson Nov 2, 2026 868 views

Question details

The user needs to modify a Word VBA macro so that it increases or decreases the current character spacing incrementally by 0.1 points, rather than setting it to a static, fixed value.

How to Adjust Character Spacing Incrementally using Word VBA Macro
Product
Microsoft Word
Device & OS
not provided
Scenario
Automating text formatting adjustments using VBA macros in a document.
Observed behavior
The current macro implementation assigns a hardcoded, fixed point value to the font spacing, overwriting existing dynamic spacing rather than adjusting it incrementally.
Before you start

Ensure you have the Developer tab enabled in your word processor to access the Visual Basic Editor, and save a backup of your document before testing new VBA macros.

Solution 1Recommended

Modify the VBA Code to Read and Increment Current Spacing

Adjust the macro to read the existing spacing value of the selected text and append a mathematical increment or decrement.

Instead of assigning an absolute value (e.g., Selection.Font.Spacing = 1.5), you must instruct VBA to retrieve the current spacing value and add or subtract your desired increment. This ensures the macro adapts to whatever text is currently selected.

1
Open the Visual Basic Editor

Press 'Alt + F11' on your keyboard, or navigate to the Developer tab and click on 'Visual Basic' to open the VBA editor.

2
Locate the Existing Macro

In the Project Explorer pane on the left, find the module containing your current character spacing macro and double-click to open the code window.

3
Update the Spacing Formula

To increase the character spacing by 0.1 points, replace the fixed assignment with: `Selection.Font.Spacing = Selection.Font.Spacing + 0.1`.

4
Add a Decrease Spacing Macro (Optional)

If you need a separate macro to reduce spacing, create a new sub-procedure and use: `Selection.Font.Spacing = Selection.Font.Spacing - 0.1`.

5
Save and Test

Save your VBA project, return to your document, select a block of text, and run the macro to verify the incremental adjustment.

Handling Mixed Spacing Values: If you select text that contains multiple different character spacing settings, `Selection.Font.Spacing` will return an 'undefined' value (wdUndefined), which may trigger a 'Type Mismatch' error. Ensure the selected text has uniform spacing before executing the macro.
Advanced Document Formatting

Use VBA Macros to Automate Formatting with WPS Writer

WPS Office provides robust support for standard VBA macros, allowing you to seamlessly execute automation scripts like incremental character spacing adjustments just as you would in Microsoft Word.

  1. 1. Enable Developer Tools: Open WPS Writer, navigate to the settings, and ensure Developer Tools are enabled to access the VBA macro environment.
  2. 2. Launch the VBA Editor: Go to the Developer tab and click on 'Visual Basic Editor', or simply press Alt + F11.
  3. 3. Insert the Incremental Code: Insert a new module, paste your `Selection.Font.Spacing + 0.1` code, save it, and run the macro on your selected text.
Fully compatible with Microsoft Word .doc, .docx, and macro-enabled .docm formats.Built-in Visual Basic Editor for creating, editing, and troubleshooting custom macros.Lightweight architecture ensures fast macro execution even in large documents.Free to download with a highly intuitive, user-friendly tabbed interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a 'Type Mismatch' error when running this spacing macro?

This error occurs if the text you selected contains mixed formatting (e.g., part of the text has 1pt spacing and another part has 0pt spacing). Because the spacing is not uniform, VBA cannot retrieve a single number to add 0.1 to. You must select text with uniform spacing or add error-handling logic to your macro.

Can I change the increment from 0.1 to a larger number?

Yes, you can modify the numerical value in the VBA code to whatever increment you need. For example, changing the code to `Selection.Font.Spacing = Selection.Font.Spacing + 0.5` will increase the spacing by half a point each time the macro is run.

How do I assign this macro to a keyboard shortcut for faster use?

Go to File > Options > Customize Ribbon, and click the 'Customize' button next to Keyboard shortcuts. In the Categories list, scroll down and select 'Macros'. Select your newly modified macro, click the 'Press new shortcut key' box, type a key combination (like Ctrl+Shift+Right Bracket), and click 'Assign'.