Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Automatically Inserting Brackets.

Automatically Inserting Brackets

by Allen Wyatt
(last updated August 25, 2012)

4

Many different documents have many different requirements for their construction. For instance, you may have a document where it is necessary to put certain recurring words within brackets so that they stand out. (Some technical manuals use this convention to designate keystrokes, such as the [Enter] key.)

If you have a need such as this, you might find it helpful to simply type your text and then go back and later add the brackets. This is where a macro can come in handy to do the adding for you. For instance, you could select the word (double-click on it) and then run a macro that would add the brackets. The following macro will easily accomplish this task:

Sub AddBrackets()
 Dim iCount As Integer
 iCount = 1
 While Right(Selection.Text, 1) = " " Or _
 Right(Selection.Text, 1) = Chr(13)
 Selection.MoveLeft Unit:=wdCharacter, Count:=1, _
  Extend:=wdExtend
 iCount = iCount + 1
 Wend

 Selection.InsertAfter "]"
 Selection.InsertBefore "["
 Selection.MoveRight Unit:=wdCharacter, Count:=iCount
End Sub

The macro compensates for any spaces or paragraph marks at the end of your selection. When you are done running it, the insertion point is left at the end of the original selection. You can assign your macro to either a keyboard shortcut or to a custom toolbar tool.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1520) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Automatically Inserting Brackets.

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

Relative Worksheet References when Copying

Copy a formula from one cell to another on the same worksheet, and Excel adjusts any relative references in the formula ...

Discover More

Identifying the Last Cell Changed in a Worksheet

When someone changes a cell in a worksheet, Excel normally goes along its merry way of keeping everything up to date. It does ...

Discover More

Highlighting Text Using the Keyboard Only

Highlighting text, using the Highlight tool, is a great way to mark up a document. Normally you need to use the toolbar tools ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Converting Strings to Numbers

When creating macros, you often need to convert a text string that contains numbers into actual numeric values. You do this ...

Discover More

Inserting Text with a Macro

Need to have your macro insert a bit of text into your document? It's easy to do using the TypeText method.

Discover More

Highlight Words from a Word List

Do you need to highlight certain words in a document, and aren't quite sure how to go about it? Using the techniques ...

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. 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 nine minus 5?

2016-02-01 07:06:28

Karol

Many thank for that makro, it really helps me, but I want to make a step forward: I have a text in table, so I want to add brackets when i highlight a column. Of course adding bracket is in one step. Every cell have one, two or three digits.
Could You help me with that?
Regards
Karol


2015-09-14 20:50:52

Matt S

Thanks again, Allen. I do appreciate it!


2015-09-10 21:27:29

awyatt

Matt: Thanks for the kind words.

Unfortunately, it won't work in Word 2008 for the Mac. That version of the program is the ONLY one in which Microsoft didn't include VBA support. Why? I have no idea, and it is very frustrating.

The only thing you can do in order to use the macros is to upgrade to a newer version of Word.

-Allen


2015-09-10 20:52:43

Matt S

Hi, Allen. I just discovered your amazing site today. Thanks for going to so much effort. It's incredible.

I need to regularly insert words in brackets, which is very time consuming. This work around seems perfect, but I was just wondering whether this macro would be compatible with MS Word 2008 for Mac Version 12.3.6. Thanks for any advice you can give.


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon 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.