How does auto Highlight all code works?

I would like to turn autohighlight for Microsoft Visual Basic for Applications (VBA)

but it doesn’t work as expected.

As I see it only works if code is indented.
But if that’s true why language recognition?

Could it be forced to recognize language?

Is it possible that first post in this thread https://online-excel-solutions.com/t/preformatted-text-vba-testing/358 is automatically preformatted?

I don’t know if the code highlighting works with indented code blocks. You may need to use three backticks eg. ```vb

Sub test()
Dim x As Long

With ActiveCell
For i = 1 To 1000
x = 91 * i
If Right(x, 2) = "22" Then
ActiveCell.Offset(m).Value = i
m = m + 1
End If
Next i

End With

End Sub
1 Like

I know that.
I meant that this would automatically recognize language and then code it.

Both codes in mine above link are just copy-paste. Without < / >.

In second post it format some parts by itself.

All </> does is indent whatever is selected four spaces.
If what is pasted in has lines that are indented four spaces they will be seen the same as if they had been selected and then indented. A common gotcha is pasted in code with # comments and underscores that get seen as intentional Markdown syntax when they are not.

I don’t know what the “generic” highlighter highlights other than Strings, Ints, and certain words common to various languages.

1 Like

IIRC, that setting is there so it will apply code formatting/highlighting to space indented code and fenced code blocks. On Meta, that setting is not enabled.

Space indented

if (true) {
  this_is_formatted = true;
}

Fenced code block

if (true) {
  this_is_formatted = true;
}

Where as on my sandbox with it enabled, I get

5 Likes

OK, so it means, when automatically set, it will change code block to fancy if space indented?

Yes. That is correct.

1 Like

This topic was automatically closed after 2652 days. New replies are no longer allowed.