4

I recently posted two answers that contained VBA code. In one of them, the syntax is highlighted and in the other one, it isn't.

Can anybody tell me why that is? I'd like it to be highlighted in both.

Answer with highlighting: Sort values based on colors, then on values using VBA code

Answer without highlighting: Automate SQL Queries with a Config File

1 Answer 1

2

I'd like it to be highlighted in both.

The question where the answer is highlighted has tag , the other doesn't.

By default, Stack Exchange uses the tags on a question to determine the language you are using.

...

It is possible to explicitly override the default highlighting language in use on the post with your language of choice for a specific code block, by specifying a language hint above the code block. Note that this is only supported when using the code fence (```) method of code formatting; since the implementation of CommonMark, doing so on code blocks using the four-space indent method is no longer supported*:

```lang-or-tag-here
code goes here
```

To add the highlights to your answer without adding the tag to the question you can add the following to your answer before the code block:

```lang-vba

I've done this for you. Note you have to also add

```lang

At the end of the code block and remove the code indenting.

Source: What is syntax highlighting and how does it work? - Meta Stack Exchange.

3
  • Great, thanks! I noticed the comments are highlighted as if they were code. Is there anything I can do to get rid of that? Mark the comment in a different way than with a single apostrophe maybe?
    – andrewb
    Commented Jan 9, 2023 at 11:24
  • Sorry, no idea.
    – DavidPostill Mod
    Commented Jan 9, 2023 at 11:32
  • No problem, thanks a bunch for your detailed answer anyway.I solved the comment problem by adding extra quotation marks around the comment. This isn't necessary in VBA editor so it might be a bug in highlight.js
    – andrewb
    Commented Jan 9, 2023 at 13:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .