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

Pasting a Graphic to Multiple Worksheets

Do you need to add a logo or other graphic to a bunch of worksheets? Here are a couple of short macros that can make quick ...

Discover More

Creating a Photo Catalog from a Folder of Photos

Excel is great for collecting all sorts of information. You might even use it to create a catalog of your photos. Working ...

Discover More

Hyphenating a Selection

Word provides a hyphenation tool that can help you hyphenate words within a document. If you want to apply hyphenation to ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (menu)

Finding Long Sentences

For certain types of writing, you may want to make sure that the sentences in your document do not exceed a certain limit. ...

Discover More

Quickly Dumping Array Contents

A VBA macro that will erase all of the information in your array.

Discover More

Editing Word's Built-in Commands

Want to configure Word to do just what you want it to? You can even go so far as to change the actual way in which Word ...

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 three more than 8?

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.