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

Printing Document Properties

Word maintains quite a bit of information about a document in a special collection of items called "properties." You can ...

Discover More

Ignoring Smart Quotes when Comparing Text

When comparing two pieces of text, you may find that Word's smart quotes can mess up the comparison. Here's a quick way to ...

Discover More

Changing the Default File Name

When you first save a new file, Word bases the name of that file on the contents of the start of the first paragraph in your ...

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)

Quickly Dumping Array Contents

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

Discover More

Repaginating in a Macro

When creating a macro that extensively processes a document, you may need to periodically force Word to repaginate the ...

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 for this tip:

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 one more than 2?

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.


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.

Links and Sharing
Share