Microsoft KB Archive/110237

= Microsoft Knowledge Base =

XL: Can't Use Line Continuation Character in Some Locations
Last reviewed: June 18, 1997

Article ID: Q110237

The information in this article applies to:


 * Microsoft Excel for Windows, version 5.0
 * Microsoft Excel for the Macintosh, version 5.0
 * Microsoft Excel for Windows 95, version 7.0

SYMPTOMS
In the Microsoft Visual Basic Programming System, Applications Edition, when you use the line-continuation character(_) in your procedure, you may receive one of the following error messages:

Syntax error

-or-

Invalid character

-or-

General protection (GP) fault (only if you use the line-continuation  character within square brackets)

CAUSE
The line-continuation character indicates that a logical line of code is continued from one physical line in the procedure to the next. Line continuation is detected in a Visual Basic procedure by searching for a space followed by an underscore ( _) at the end of a line. These characters are then removed before the line of code is parsed. However, you cannot use the line continuation character in the following locations in your code.

Between Quotation Marks
A = "This is an example of assigning a very long _  string variable"

Between a Colon and an Equal Sign
Cells.CheckSpelling CustomDictionary:="CUSTOM.DIC", IgnoreUppercase: _ =False, AlwaysSuggest:=True

Within Square Brackets
[Test _ ]

WORKAROUND
You should only use the line continuation character in your procedure when you have a very long line of code that is wider than your screen. In general, you can use the line continuation character in the following locations:

- Before or after a comma

- Before or after an equal sign (except between a colon and equal sign)

- Before or after a colon and an equal sign (:=)

- Before or after an operator (such as &, +, -, LIKE, NOT, AND) The following are examples of using the line continuation character that do not cause an error message when they are run:

A = "This is an example of assigning a very long " & _ "string variable"

A = _ "This is an example of assigning a very long string variable"

A _ = "This is an example of assigning a very long string variable"

Cells.CheckSpelling CustomDictionary:="CUSTOM.DIC", _ IgnoreUppercase:=False, AlwaysSuggest:=True

Cells.CheckSpelling CustomDictionary:="CUSTOM.DIC", IgnoreUppercase _ :=False, AlwaysSuggest:=True

Cells.CheckSpelling CustomDictionary:="CUSTOM.DIC", IgnoreUppercase:= _ False, AlwaysSuggest:=True

ActiveSheet.PageSetup.LeftHeader = _ "this is an example of a very long left header for your worksheet"

Answer = NOT _ (A<B) NOTE: Do not use the line-continuation character within square brackets. There is no workaround for this behavior.

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

NOTE: Though you can type the lines in the above examples without the line-continuation character as one physical line, type them exactly as shown above to illustrate using the line-continuation character.