the below pertains to the flag language: lang-vba
, which I have since been informed is not actually a flag, and for my use I should have been using language: lang-vb
VBA Code that uses conditional formatting, comments, date literals or open-ended strings is not highlighted correctly. For example,
is not Highlighted like it is in the Microsoft Office Visual Basic Editor
What is happening?
It would seem that instead of properly identifying '
as the comment starting literal, it was incorrectly assigned to being a char
literal (note that VBA does not support char
literals in any fashion). It would seem that the #
character was then assigned to being the comment starting literal, instead of the Conditional Compilation literal.
Of significant not is that #
also serves as the wrapping literal for declaring date type objects inline as seen in the example below
Note that the #12:00:01 AM#
is highlighted to indicate that it is commented out, rather than being represented like any other string or number literal
Beyond this, VBA does not support multiline string literals of any form, and in certain cases supports string literals without a terminating "
. However, the current Prettify.js
setup for VBA supports multiline strings, meaning that you an end up with code blocks that look like the one below on our site.
Note that line 3 is included in the string highlighting, despite not being a string
What needs to be changed?
In the Prettify.js
config,
The comment literal needs to be changed from
#
to'
(which can be escaped by wrapping string)The
'
char(?) literal needs to be removed, as VBA does not support charsRemoval of highlighting for multiline strings should be considered (if there are no characters, such as
,
or)
, expected after the end of a VBA string, VBA will autoformat to add a trailing"
at the end of the line, and they are otherwise illegal strings)It should be considered highlighting any, non-string, section of code which is wrapped in
[...]
(where...
is some expression) in the same light red color as the string and number literals are, as this equivalent to a string which is wrapped in anApplication.Evaluate("...")
call
Therefore, any bugs and feature requests regarding syntax highlighting cannot be handled by Stack Exchange and should be directed to the team behind Google Code Prettify.
\$\endgroup\$<!-- Language: vba -->
before the code block, it highlights correctly. \$\endgroup\$