Skip to content

v0.1.0 - VS Code encoding hint for non-ASCII VBA

Latest

Choose a tag to compare

@lavignolle lavignolle released this 16 May 23:26
· 50 commits to main since this release
0841cfd

First tagged release. Fixes #1 (reported by @Wichamir): non-ASCII characters in VBA source (Polish a/c/e/l, French accents, Euro sign, smart quotes, etc.) showed as mojibake when exported .bas/.cls/.frm files were opened in VS Code.

What changed

VBA's native comp.Export writes files in the system ANSI codepage (Windows-1250 for Polish locales, 1252 for Western European, etc.). VS Code defaults to UTF-8 and was misreading the bytes even though the round-trip back into the VBA editor was correct.

Rather than re-encode the files (the obvious approach - tried in PR #2 and abandoned because it broke VBComponents.Import, the .frm/.frx pairing, and class per-member attributes), this release leaves the bytes exactly as VBA emits them and instead drops a .vscode/settings.json next to .gitignore telling VS Code to read VBA files in the local codepage.

  • New WriteVSCodeSettings helper detects the system codepage via Win32 GetACP and writes a .vscode/settings.json with:
    • [vba] files.encoding pinned to the matching encoding name
    • files.associations pinning .bas/.cls/.frm to the vba language so the per-language override applies even without a VBA extension installed
    • files.autoGuessEncoding: false (necessary because pure-ASCII files parse cleanly as UTF-8 and the guesser would override the hint)
  • Codepages 1250-1258 plus CJK (932/936/949/950) and Thai (874) are mapped explicitly; unknown codepages fall back to windows1252
  • File is created once per repo, never overwritten - same policy as .gitignore and .gitattributes. Commit it to the repo so collaborators on the same codepage see files correctly out of the box.
  • No change to how .bas/.cls/.frm files themselves are written.

Known limitation

Cross-locale collaboration (a Polish-authored file containing a/c/etc. opened by a Western European contributor) still requires both contributors to run with the same system codepage. Solving that properly means parsing/regenerating the VBA file format ourselves - out of scope for this release.

Install

Download VBA Sync.xlam from the assets below, unblock it (right-click -> Properties -> Unblock), drop into %APPDATA%\Microsoft\AddIns\, and restart Excel.