Line Continuation

The very nature of Word VBA syntax often leads to long lines of code, which can be difficult to read, especially if we need to scroll horizontally to see the entire line. For this reason, Microsoft recently introduced a line-continuation character into VBA. This character is the underscore (_), which must be preceded by a space and cannot be followed by any other characters (including comments). For example, the following code:

	ActiveDocument.Paragraphs(1).Alignment = _
	wdAlignParagraphCenter

is treated as one line by Word.

A line-continuation character cannot be inserted in the middle of a literal string constant, which is enclosed in quotation marks.

Get Writing Word Macros, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.