Dutch Gemini's Weblog Pages

January 26, 2010

Expand and Compress text in Word with two simple macros

Filed under: Programming,VBA,Word — dutchgemini @ 12:27 pm

When you are writing your documents using Microsoft Word you may have noted that the text wrapping at the right edge of your margins sometimes leaves a single word on the next line. This is obviously not a bug of Word but the visual result of this single word hanging at the bottom of the paragraph is not so nice.

To pull that ugly-looking single word back to the previous line you can try rephrasing the paragraph (removing or adding words) but if that’s not possible then you can try reducing (aka compress) or increasing (aka expand) the character spacing of the paragraph to make it fit. Small changes in character spacing are often not percepted by readers.

In Word, this option is found under the Fonts dialog. Word accepts changes in character spacing by very small decrements or increments. However, this is a trial-and-error method and sometimes before you are satisfied with the result you may need to repeatingly decrement or increment the character spacing using the dialog.

In desktop publishing software this functionality is usually available as a standard function on the menu or toolbar or as a keyboard shortcut, but not in Word. With two little macros that decrement or increment the character spacing interactively, hooked to the command bar, the ribbon or a keyboard shortcut, you obtain this functionality and you get an immediate visual feedback of the effect.

Create these macros FontSpacingCondens and FontSpacingExpand somewhere in Word in a place that makes them permanently available (see your documentation):

Public Sub FontSpacingCondens(Optional Unit As Single = 0.1)
On Error Resume Next
    If (Selection.Type = wdSelectionNormal) Then Selection.Font.Spacing = (Selection.Font.Spacing - Unit)
End Sub

Public Sub FontSpacingExpand(Optional Unit As Single = 0.1)
On Error Resume Next
    If (Selection.Type = wdSelectionNormal) Then Selection.Font.Spacing = (Selection.Font.Spacing + Unit)
End Sub

The above code will decrement or increment the actual character spacing. The optional parameter called Unit sets a default value of 0.1. This is equivalent to a 0.1 point decrement or increment which is Word’s dialog default.

Add these 2 macros to the toolbar or ribbon and/or assign 2 keyboard shortcuts to them. I selected to use [Alt+Shift+Left] for the FontSpacingCondens macro and [Alt+Shift+Right] for the FontSpacingExpand macro.

To see the effect, select a range in the document and press one of the buttons or keyboard shortcuts.




  1. Thanks, just what was needed. VERY HELPFUL. You help appreciated!

    Comment by guest — October 18, 2010 @ 5:35 pm | Reply

  2. This is great help thanks

    Comment by sarah kaye — October 10, 2012 @ 6:30 am | Reply

  3. Thanks for this quick macro. Even years after still relevant and useful. All the best Dutch and thanks for that sharing spirit !

    Comment by Gaspard — August 28, 2016 @ 5:06 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: