piapia123
en

VBScript Code Formatter

Format

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

Indentation cleanup for VBScript. Depth is worked out by pairing block keywords — `Sub`, `If … End If`, `For … Next`, `Do … Loop`, `Select Case … End Select`. ⚠️ One thing to be clear about: this page has no syntax tree. The other seven language formatters here (Python, Ruby, Java, C, C#, PHP, Perl) really do parse your code with tree-sitter, and the parser supplies the block boundaries. VBScript cannot — no grammar exists: the public tree-sitter grammar collections do not include it, and the one VBA grammar on npm is a native addon that cannot run in a browser. So this falls back to keyword pairing. That is far better than counting brackets — it recognises fake keywords inside strings and comments (`"End If"` is not a closer), it recognises single-line `If` (`If x Then y = 1` has no `End If`), and it understands `_` continuations — but it cannot answer questions like "which block does this `}` belong to". For code that is itself syntactically wrong, the indentation here may not match your intent, whereas the other seven still get block boundaries from the parser. That is stated plainly rather than hidden. ⚠️ Only the leading whitespace of each line changes — not a character inside it. Continuations, strings and comments are never touched. The upside is that it downloads nothing (the other seven each pull a grammar file of a few hundred KB up to 5 MB), so it works the moment you open it.

Features

  • Indents by pairing Sub / Function / If / For / Do / While / Select Case / With / Class
  • Recognises single-line If (`If x Then y = 1` does not open a block)
  • Keywords inside strings and comments are not paired
  • Lines continued with a trailing `_` are kept exactly as written
  • Only leading whitespace changes; not a character inside a line
  • Indent with 2 spaces, 4 spaces or tabs
  • Case-insensitive keywords (as VBScript itself is)
  • Syntax-highlighted output
  • Runs entirely on your device — no upload, and no grammar file to download

How to use

  1. Paste the code into the left pane
  2. Pick an indent width
  3. Press Ctrl/⌘ + Enter or click Run
  4. Copy the result

FAQ

Is this the same as the Python / Java formatters on this site?
No — and the difference in capability is real, so here it is plainly. Those tools use tree-sitter to build a syntax tree, and each line’s depth comes from the grammar it belongs to — the parser knows which `}` closes which block. No usable grammar exists for VBScript (the public tree-sitter collections do not include it, and the only VBA grammar on npm is a native addon that cannot run in a browser), so this one uses keyword pairing: it recognises pairs like `If … End If` and `For … Next` and derives depth from those. The difference shows on syntactically wrong code: a syntax tree still tells you where the block boundary is regardless, while keyword pairing can only tell you what the first word of the line is. So if the code is itself malformed, the indentation here may not match your intent.
My code uses single-line If — will that break it?
No. In VBScript, `If x Then y = 1` has no `End If`; treating it as a block opener would push every following line deeper and deeper. The test here is whether the line ends with `Then`: `If x Then` opens a block, `If x Then y = 1` does not. A form like `If x Then ' note` still counts as a block — the comment is stripped before the decision is made.
Can keywords inside strings and comments be mistaken for structure?
No. Comments are stripped and string literals are understood before any structural decision: the `End If` in `s = "End If"` is not a keyword, and `' End Sub` is a whole-line comment. Doubled quotes inside a string (`"he said ""hi"""`) are treated as one escaped quote, per VBScript’s own rule, so the string does not end early.
Will it change what my code does?
No. Only the leading whitespace of each line is touched — not one character inside a line, no reordering, no re-wrapping, no line removal, nothing inside strings or comments. Lines continued with a trailing `_` are kept whole, because that indentation is yours and re-laying it out would split one statement in two. By the same token, it cannot add missing syntax. It is an indentation tool, not a repair tool.

Related tools