
Tips.Net > WordTips Home > Editing > Automatic Non-breaking Spaces in Dates
Summary: It drives some people crazy to have a date break across two lines. If you find yourself in this mindset, then you’ll appreciate the ideas presented in this tip for easily making sure that a date stays all on the same line. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
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 use 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--AutoText. This solution actually can work very well, but it will require some differences in how you type dates. The best solution is to create 12 AutoText entries, 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. (You see the control for this if you choose Tools | AutoCorrect | AutoText. It is the top check box on that tab.) If AutoComplete is turned on, 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:
Public Sub DatesWithNonBreakingSpaces()
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
' clear the parameters from the Find/Replace dialog
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
Tip #1749 applies to Microsoft Word versions: 97 2000 2002 2003
Step Up and Take Control! Subscribers to WordTips know just how valuable a resource it is. WordTips Premium provides twice the number of exceptional, easy-to-understand tips every week in an ad-free newsletter, as well as substantial discounts on WordTips archives and e-books.
Check out WordTips Premium today!
Thousands of WordTips, available for immediate download. Have all the Microsoft Word info you need, right at your fingertips. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips