
Tips.Net > WordTips Home > Text Boxes and Frames > Text Boxes > Centering a Text Box
Summary: Different ways you can move a text box to the center of the page. (This tip works with Microsoft Word 95, Word 97, Word 2000, Word 2002, and Word 2003.)
Many people wrote in this week with different ideas on how to center a text box between the margins on a page. For many people, centering is definitely a "hit and miss" affair, as was indicated by the potential solutions. Some even suggested simply converting the text box to a frame, and then centering. (It is much easier to center a frame than a text box.) Such solutions do not, however, satisfy everyone. You may want a very precise centering, and you may not want to give up the versatility offered by text boxes when compared to frames.
There are two ways to center items horizontally: you can either center on the page itself, or you can center between margins. If you are using Word 95 and you want to center a text box on a page (irrespective of the margins), then you can follow these steps:
Beginning with Word 97 the process is just slightly different, due to large changes made in the Drawing toolbar:
Note that these steps produce a text box that is centered on the page, not between the margins. Of course, if you have equal margins on the left and right side of your page, then there is no difference between centering on the page and centering between margins. If your margins are different, however, you may want to center between the margins so that your text box appears centered when compared to the text on the page. If you want to do this, you need to rely on a macro--there is no way to do it using menus within Word.
Unfortunately, creating such a macro in WordBasic is dang near impossible. This is because if you select the text box you want to center and then run the macro, you cannot retrieve the formatting options to determine margin settings. (The FilePageSetup dialog cannot be retrieved when you have a text box selected.) Conversely, if you run the macro without the text box selected (so you can get the page settings), then the macro has no way of knowing which text box you want to center.
VBA is a different story. You can rather easily create a macro that will center the currently selected text box between your margins. The following macro, CenterTextBox, will do just that:
Sub CenterTextBox()
Dim MyPageWidth As Single
Dim MyLeftMargin As Single
Dim MyRightMargin As Single
Dim MyGutter As Single
Dim MyTextArea As Single
Dim MyGraphicWidth As Single
Dim DistanceFromLeftMargin As Single
MyPageWidth = ActiveDocument.PageSetup.PageWidth
MyLeftMargin = ActiveDocument.PageSetup.LeftMargin
MyRightMargin = ActiveDocument.PageSetup.RightMargin
MyGutter = ActiveDocument.PageSetup.Gutter
MyTextArea = MyPageWidth - MyLeftMargin - MyRightMargin - Gutter
' Get width of text box itself
MyGraphicWidth = Selection.ShapeRange.Width
' Calculate distance from left margin
DistanceFromLeftMargin = (MyTextArea - MyGraphicWidth) / 2
' Make the settings necessary
Selection.ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
Selection.ShapeRange.Left = DistanceFromLeftMargin
End Sub
Tip #1056 applies to Microsoft Word versions: 95 97 2000 2002 2003
More Power! For some people, the prospect of creating Word macros can be scary. WordTips: The Macros can help you conquer your fears and you'll discover you're much more confident and productive as you make Word do exactly what you want. This is an invaluable source for learning macros. You are introduced to the topic in bite-sized chunks, pulled from past issues of WordTips. Learn at your own pace, exactly the way you want.
Check out WordTips: The Macros today!
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
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