
Tips.Net > WordTips Home > Macros > Automatically Inserting Brackets
Summary: Some editorial styles require the use of brackets around words, for instance to indicate which keys on a keyboard should be pressed. If you want a quick way to add brackets around selected text, this tip is for you. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
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.
Tip #1520 applies to Microsoft Word versions: 97 2000 2002 2003
Ultimate Library! The most amazing collection ever offered in the history of WordTips places every tip—present and historical—at your fingertips. Check out the WordTips Ten-Year Library.
Word includes two powerful search engines. Do you know how to use them both? You can discover new knowledge with WordTips: Find and Replace. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Pet Tips
Word2007 Tips
WordTips