Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Automatic Non-breaking Spaces in Dates.

Automatic Non-breaking Spaces in Dates

by Allen Wyatt
(last updated December 31, 2016)

3

When you enter a date into a document, it would be very handy for Word to automatically place a non-breaking space between the month and the day of the month. Thus, "January 22" would have a non-breaking space between the "y" and the "2". In this way, the month and day would always appear together on the same line.

Unfortunately, Word doesn't do this by default. This means that you have several different ways you can use Word's built-in tools to solve the situation.

The first possible solution is to try using Word's AutoCorrect feature. This feature is not well suited for doing this task, however. Why? Because AutoCorrect only kicks in after Word figures you are finished with a word—in other words, when you type the space after the word or some other terminating character, such as a punctuation mark. Thus, if you wanted to replace "January" with "January" followed by a non-breaking space, you would actually end up with two spaces after the word—the non-breaking space in the replacement text and the space you typed in the course of, well, typing.

This brings us to the next potential solution—Building Blocks. This solution actually can work very well, but it requires some differences in how you type dates. The best solution is to create 12 Building Blocks, each saved under the three-character name of the 12 months. Thus, the entry for "jan" would be "January" followed by a non-breaking space.

Why use three characters instead of more? Because Word has another feature called AutoComplete. If AutoComplete is turned on (and it is turned on by default), then Word tries to "guess" what you are typing and suggest the rest of the word or phrase. It does this automatically for dates, but it doesn't kick in until you type the fourth character in a month that is longer than five characters. Thus, Word suggests "January" as a completion when you type "Janu", but it won't suggest "March" as a completion when you type "Marc".

If you use three characters for your month-and-non-breaking-space combination, then you can type "Jan" and press F3, resulting in the desired combination, without extra spaces. The change in how you type, of course, is that you must remember to only type three characters and then press F3.

If you don't like to remember such changes in how to type, you can easily create a macro that will go through a document and replace any spaces following a month name with a non-breaking space. The following is very handy for this purpose:

Sub MonthsWithNonBreakingSpaces()
    Dim sMonth As String
    Dim iMonth As Integer

    Selection.HomeKey unit:=wdStory
    For iMonth = 1 To 12
        With Selection.Find
            .ClearFormatting
            .Text = "(" & MonthName(iMonth, False) & ")( )([0-9])"
            .MatchWildcards = True
            With .Replacement
                .ClearFormatting
                .Text = "\1^s\3"
            End With
            .Execute Replace:=wdReplaceAll
        End With
    Next iMonth
End Sub

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11186) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Automatic Non-breaking Spaces in Dates.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Starting Microsoft Graph

Microsoft Graph is a simplistic graphic tool that you can use to quickly add graphs to your document. Here's how to start the ...

Discover More

Positioning the Footnote Separator

The Footnote Separator, as its name implies, separates the footnotes on each page from the text on that page. If the ...

Discover More

ExcelTips Ribbon 2014 Archive (Table of Contents)

ExcelTips is a weekly newsletter that provides tips on how to effectively use Microsoft's best-selling spreadsheet ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Adding Tabs at the Beginning of a Line

Press a tab at the beginning of a paragraph, and Word normally assumes you want to indent the paragraph. If you don't like ...

Discover More

Jumping to the End of a Word

Using shortcut keys to navigate through your document is really handy. One navigation shortcut that Word doesn't provide is ...

Discover More

Viewing More of the Left Margin Area

When working in Draft or Normal view, you may want to view the area just to the left of the document's left margin. Here's a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 2?

2017-08-09 14:51:49

Peter

Been trying for a few hours. Any way to get the month, day, and year all on the same line?


2017-05-02 03:12:25

Samntha HH

Nonbreaking space between month and date as well. Put day before month so code is actually usable for people:

Sub MonthsWithNonBreakingSpaces()
Dim sMonth As String
Dim iMonth As Integer

Selection.HomeKey unit:=wdStory
For iMonth = 1 To 12
With Selection.Find
.ClearFormatting
.Text = "([0-9])( )(" & MonthName(iMonth, False) & ")( )([0-9]{2})"
.MatchWildcards = True
With .Replacement
.ClearFormatting
.Text = "\1^s\3^s\5"
End With
.Execute Replace:=wdReplaceAll
End With
Next iMonth
End Sub


2016-12-31 09:41:17

Michael Harris

An alternative to the above macro would be one to make sure from the outset that there are no spaces in the date string where a break could occur. Below is a macro I wrote some time ago to ensure this. It inserts the date in the MS long format and then edits the inserted date to remove breaking spaces and insert the appropriate ordinal indicator. It stll works under all the latest versions of MS Word.
Although this uses tha English version of the MS long format it can easily be adapted to the american month/day/year, and added to the QAT

Public Sub InsertTheDate()
'
' Insert the Date Macro
' Macro created 17/05/00
'
If Documents.Count >= 1 Then
Dim DateType$
WordBasic.InsertField Field:="DATE @" + Chr(34) + "d MMMM yyyy" + Chr(34) + " * MERGEFORMAT"
WordBasic.WordLeft 3
WordBasic.CharRight 1, 1
WordBasic.UnlinkFields
WordBasic.CharRight 1
WordBasic.WordLeft 1
WordBasic.EditClear -1
WordBasic.Insert " "
WordBasic.WordLeft 1
WordBasic.EditClear -1
Select Case WordBasic.Day(WordBasic.Now())
Case 1, 21, 31
DateType$ = "st" + Chr(160)
Case 2, 22
DateType$ = "nd" + Chr(160)
Case 3, 23
DateType$ = "rd" + Chr(160)
Case Else
DateType$ = "th" + Chr(160)
End Select
WordBasic.Insert DateType$
WordBasic.CharLeft 3
WordBasic.CharRight 2, 1
WordBasic.Superscript
WordBasic.WordRight 3
WordBasic.Insert " "
End If
Else
MsgBox "No documents are open"
End If
End Sub

====================================

As a small bonus here is an equivalent macro for the days of the week.

Public Sub InsertDayOfTheWeek()
'Insert The Day Of The Week
' Macro created 17/05/00
'
Dim Thisday
ReDim days__$(7)
days__$(1) = "Sunday": days__$(2) = "Monday": days__$(3) = "Tuesday"
days__$(4) = "Wednesday": days__$(5) = "Thursday"
days__$(6) = "Friday": days__$(7) = "Saturday"
Thisday = WordBasic.Weekday(WordBasic.Now())
WordBasic.Insert days__$(Thisday) + " "
End Sub



This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.