Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Continuing Macro Lines.
by Allen Wyatt
(last updated September 27, 2014)
When you are creating a VBA macro, you may run into some very long lines. The VBA Editor will handle long lines, but it is usually a pain to scroll the screen left and right to review a line. Some programming languages (Such as C or Perl) allow you to continue program lines simply by pressing Enter and continuing with the line.
VBA, however, requires a special character sequence to signify that you want to continue the current program line on the next. This sequence consists of a space and an underscore. Consider the following example code:
With Selection.ParagraphFormat.TabStops .ClearAll .Add Position:=InchesToPoints(Val(MyTab)), _ Alignment:=wdAlignTabDecimal, _ Leader:=wdTabLeaderSpaces End With
This code continues a program line over three physical lines by using the space and underscore at the end of each line being continued. You can use the continuation characters to continue any programming lines you desire. The only thing you need to remember is that you can only use the characters for continuation purposes if you place them between regular tokens or keywords used in the program line. If you place them in the middle of a keyword or in a string (between quote marks), VBA won't know what you intended, and may generate an error.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13258) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Continuing Macro Lines.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
Associate a macro with a shortcut key, and at some time you may want to break that association. (Perhaps so the shortcut ...Discover More
Word collects a wide range of statistics about your documents, but one of the things it doesn't collect is how many times ...Discover More
One of the common things done in macros is to somehow "process" documents, which often means moving the insertion point ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.