VS Code and the CLI
VS Code extension
日本語 | English
RAS is a better VBA: a language with a TypeScript-like syntax that transpiles to VBA (.bas / .cls). This extension adds RAS (.ras / .d.ras) language support to Visual Studio Code.
The extension itself is deliberately thin. All it does is provide syntax highlighting and start the ras binary as a language server (ras lsp --stdio) and connect to it. Completion, quick info, parameter info, diagnostics, go to definition, rename, inlay hints, semantic highlighting, CodeLens, formatting and the rest are all provided by the language server.
Requirements
- Visual Studio Code 1.90 or later
- The
rasexecutable (ras.exeon Windows). Put it in a folder onPATH, or set its path with the settingras.path.
When ras is not found, an error message is shown; its [Open Settings] button lets you set ras.path. Syntax highlighting works without ras.
Features
- Syntax highlighting of
.rasfiles (based on the TextMate grammar of TypeScript, withbyref/byval/inline/noinline/resume, the basic types of RAS, the numeric literal suffixes123L/1.5f/2d/1.5m, decorators, anddeclare module/declare struct) - Auto-closing of comments and brackets, continuation of
/** */doc comments, indentation, folding - The full IntelliSense of the language server (it starts automatically in a workspace with a
ras.toml, or when a.rasfile is opened; it does not start in a workspace with neither) - Creating a new project (a workbook and sources)
- The sync status in the status bar
- Debugging with breakpoints (stepping, variables and watch expressions, stopping on exceptions). User forms are shown and run in a VS Code panel
- A user form designer (visual editing of
forms/*.form.json) - Running and debugging tests and showing their results in the Test Explorer (
ras test) - Display language: the extension, the language server and the
rasprocesses it starts use Japanese when VS Code's display language is Japanese, and English otherwise
Commands
These are run from the Command Palette. Each of them only asks the language server to do the work.
When an empty folder is open (including a folder that holds only hidden files such as .git and Excel workbooks), the Explorer's title bar shows a [Create RAS Project] icon button (the RAS logo) and the status bar shows [Create RAS Project]. The Explorer of a window without a folder shows the same button (you choose the folder to create the project in, and the folder is opened afterwards).
When a folder with a ras.toml is open, the Explorer's title bar (the row with the project folder's name) shows the [New Standard Module] and [New User Form] icon buttons. Both can also be run from a folder's context menu.
| Command | What it does |
|---|---|
Create RAS Project |
Creates a RAS project (ras init: ras.toml, src/main.ras, AGENTS.md, .gitignore) and a workbook in a folder, writes the sample code into the workbook (ras pack, which also creates the files of the workbook's sheets and ThisWorkbook, objects/Sheet1.ras and objects/ThisWorkbook.ras), and opens src/main.ras and the workbook's sheet preview. The workbook can be a new empty macro-enabled workbook (named after the folder by default), a workbook in the folder, or a workbook from elsewhere (copied into the folder). An .xlsx is converted to an .xlsm of the same name (the original .xlsx is not changed). Hand-written VBA in an existing workbook is imported into the project before writing (the same as ras pack; the workbook as it was before is kept in build/backup/). The project goes to the folder right-clicked in the Explorer, else a workspace folder without a ras.toml, else a folder you choose. In a workspace without a ras.toml, it can also be run from a folder's context menu in the Explorer. With an English display language, the new project uses code page 1252 and English comments. |
RAS: Show Generated VBA |
Shows the VBA generated from the RAS file being edited in a read-only editor beside it, and highlights the line that corresponds to the cursor. Can also be run from the editor's title bar and context menu. |
RAS: Sync with Workbook |
Applies the VBA generated from the saved sources to the workbook open in Excel right away. When the workbook is not open in Excel (including on systems other than Windows), it writes straight to the workbook file like ras pack (offline writing; the output goes to RAS in the Output panel). When modules were edited in Excel (VBE), it asks whether to overwrite them. While a project is open, the [Sync with Workbook] icon button in the Explorer's title bar runs it too. |
RAS: Open in Excel |
Opens the workbook in Excel (or brings it to the front when it is open) and syncs. |
RAS: Run Macro |
Choose a macro from the list; it is synced and then run in Excel. |
RAS: Run Form in Excel |
Choose a user form; it is synced and then shown in Excel (Windows only). Can also be run from the designer's title bar. |
RAS: Debug Form |
Shows the user form open in the designer in a VS Code panel and debugs it. Run from the designer's title bar. |
RAS: Show Workbook in Sheet Preview |
Shows a workbook (.xlsx / .xlsm) in an Excel-like sheet preview in a panel. Can also be run from a workbook's context menu in the Explorer. The workbook shown can be edited in the sheet preview (see "Editing in the sheet preview" below; the workbooks a run saved under build/ and the view while debugging are read-only). |
RAS: Show Sheet Preview |
On the file of a sheet (a file in objects/ named after the sheet's code name, like objects/Sheet1.ras), shows the project's workbook (project.workbook of ras.toml) in the sheet preview, open at that sheet. Run from the editor's title bar (the table icon), the editor's context menu, or a file's context menu in the Explorer. It shows the saved workbook file, which can be edited in the grid. |
RAS: Add Sheet / Copy Sheet / Delete Sheet / Rename Sheet |
Changes a sheet of the workbook and its file (objects/<CodeName>.ras) together. Run from the context menu of objects/ and its files in the Explorer, of the tab of a sheet's file, or of a sheet tab in the sheet preview. When the workbook is closed, the workbook file is rewritten; when it is open in Excel, Excel does it (Windows only). Deleting a sheet whose file has code or that other things refer to asks for confirmation, with the reasons. Changing the code name also renames the file and the references in the sources (Sheet1.…). When a file of objects/ is renamed or deleted in the Explorer, you are asked whether the sheet should follow. |
RAS: Show the Failed Test's Workbook in Sheet Preview |
Shows the workbook of a failed test (build/test/workbooks/) in the sheet preview, with the cells changed since the test started marked. Can also be run from the button and the context menu of a failed test's message and from the context menu of the test in the Test Explorer (see "Running tests" below). |
RAS: Generate Test |
Adds the skeleton of a test of the function at the cursor (an exported function of a module in src/) to test/<module>.test.ras and opens it (see "Generating tests" below). Can also be run from the editor's context menu. |
RAS: Restart Language Server |
Restarts the language server. |
RAS: Start Debugging |
Choose a function and debug it (the same as F5). Can also be run from the editor's title bar. |
RAS: New Standard Module |
Creates and opens src/<name>.ras. The VBA module name follows from the file name (str_util → StrUtil). Run on a folder under src/ in the Explorer, it creates the file in that folder. |
RAS: New User Form |
Creates forms/<name>.form.json and the RAS code-behind forms/<name>.ras, and opens the form in the designer. |
RAS: Open in Designer |
Opens the FormSpec open in a text editor in the designer. |
RAS: Open JSON |
Opens the FormSpec open in the designer in a JSON text editor beside it. |
Editing in the sheet preview
A workbook shown with "RAS: Show Workbook in Sheet Preview" or "RAS: Show Sheet Preview" can be edited the way it is in Excel. At the top is the same ribbon as Excel's (the Home, Insert, Formulas, Data and View tabs; the "Insert" of Excel's Developer tab is among the controls of the Insert tab, and View Code is on the Shape Format tab), with the buttons where Excel has them. Double-clicking a tab collapses the ribbon. The edits are written to the workbook file by ras book edit (specification §14.14). Only the changed cells are written back, so the VBA project, shapes, controls and formatting stay as they are.
The list of operations (ribbon, keys, mouse), how the edits are written and what cannot be done yet are in Editing a workbook of the reference (the "Book" tab of the playground works the same way). What is particular to the sheet preview of VS Code:
- Every edit rewrites the workbook file (there is no Save). For the project's workbook, the previous file is kept in
build/backup/. - A workbook open in Excel cannot be edited (the reason is shown below the sheet preview). Close it in Excel first.
- With two or more cells selected, the status bar shows the count of the data and the average and sum of the numbers. A cell with a note has a red triangle and shows the note when the mouse is over it. Clicking a hyperlink cell follows the link (VS Code opens http, https and mailto). Change the zoom with "Zoom" on View, at the right of the status bar, or with Ctrl+wheel. "Show Formulas" on Formulas (Ctrl+`) shows the formulas.
- The events of shapes and controls are written in the sheet's file (
objects/<CodeName>.ras), as in the form designer. For an ActiveX control, the@on("CommandButton1.Click")handler is opened (added when there is none; "Assign Event…" lets you choose the event). For a shape, picture, chart or form control, "View Code" opens the function assigned to its click event (the selection event for list and combo boxes, the change event for spin buttons and scroll bars; Excel's "Assign Macro"); when none is assigned, "Assign Click Event" addsexport function <name>Click()and assigns it in the workbook ("Assign a function to …" lets you choose from the functions ofobjects/andsrc/). - While the sheet preview has the focus, Ctrl+R, Ctrl+D, Ctrl+Y, Ctrl++, Ctrl+-, Ctrl+B, Ctrl+I, Ctrl+U, Ctrl+5, Ctrl+1, Ctrl+Shift+L, Ctrl+F, Ctrl+H, Ctrl+G, Ctrl+K, Ctrl+T, Ctrl+L, Ctrl+F3, Shift+F2, F4, and F5 when not debugging, are operations of the sheet preview, not VS Code commands (F5 is Go To, not Start Debugging; while debugging, F5 still continues).
Run mode of the sheet preview
In the sheet preview of the project's workbook, the switch at the right end of the ribbon's tabs switches between "Edit" and "Run" (specification §14.10.10). In run mode the project is built and run on the Excel stand-in, and what you do on the sheet raises events (as in Excel with design mode off). "▶ Run mode" is shown at the left of the status bar.
| What you do | Events raised |
|---|---|
| The workbook (run mode starts) | Workbook.Open |
| Switching sheets | Deactivate / Activate |
| Selecting cells | SelectionChange |
| Entering into a cell, Delete | Change (and Calculate when formulas were recalculated) |
| Double-clicking or right-clicking a cell | BeforeDoubleClick / BeforeRightClick (cancel cancels the editing or the menu) |
| Clicking an ActiveX control | GotFocus, MouseDown, MouseUp, Click (LostFocus when the focus moves on). Check boxes, option buttons and toggle buttons are turned on / off, spin buttons and scroll bars change their value, and list boxes select an item (raising Change too) |
| Clicking an ActiveX text box or combo box | An input box (and the list of items for a combo box) is shown below it. Enter or choosing an item changes the value and raises Change |
| Clicking a shape or a form control | After the value of a form control changes (check box, option button, list, drop-down, spin, scroll), the @on("<name>.Click") handler or the assigned macro |
- The workbook file is not changed. The cells the program changes are shown in the sheet preview and saved to
build/debug/workbooks/when you leave the mode. Back in edit mode, the content of the workbook file is shown. - In run mode you can enter and delete in cells, select, switch sheets, and click objects. Do other edits in edit mode.
- The state of controls (value, caption, items, visibility) can be read and written by the program, as in
Sheet1.CheckBox1.value, and changing it raises the control's events. The sheet preview is drawn again with that state (specification §14.10.8). debug.printgoes to RAS Debug in the Output panel, andmsgBoxis shown as a notification. Errors in handlers are shown as notifications.- After changing the sources, switch to run mode again to rebuild.
Switching the run target
The ▶ item in the status bar (or RAS: Switch Run Target) chooses where "Run" runs a function, out of three. The choice is saved in the workspace setting ras.run.target.
| Target | "Run" | "Debug" |
|---|---|---|
| Excel stand-in | The program built to JavaScript runs on RAS without Excel (it reads workbook of ras.toml; the changed workbook is saved in build/debug/workbooks/) |
The Excel stand-in too |
| Excel (COM) | The program built to JavaScript works on the real Excel over COM (Windows only) | Excel (COM) too |
| Excel (VBA) | The generated VBA is synced to the workbook and runs inside Excel (Windows only; the former "Run in Excel") | Follows the setting ras.debug.excel |
The ▶ CodeLens above functions and the ▶ button of the editor title bar run on the chosen target. A launch.json configuration with excel keeps its own value.
Debugging
Put a breakpoint in a .ras file and press F5: the project is built, you choose the function to run, and debugging starts.
The CodeLens shown above a function starts that function directly.
▶ Run in Excel | ⚙ Debug
export function rebuildReport() {
(The CodeLens titles come from the language server, in the display language.)
- Run in Excel (Windows only): syncs to the workbook and runs the function as a macro in Excel itself (the same as
RAS: Run Macro; the workbook must be open in Excel). Shown on the functions that are published as macros (functionsexported without arguments or a return value,@macrofunctions, top-level statements). - Debug: starts debugging with that function (the same as F5, without choosing the function). Shown on functions without arguments and on top-level statements.
In the code of a user form (forms/<name>.ras), the same CodeLens is shown at the top of the file and shows and runs the form. In the designer, the buttons of the title bar (▶ and ⚙) do the same.
- Run in Excel (Windows only): syncs to the workbook and shows the form in Excel itself. Until a modal form is closed, the next sync waits.
- Debug: shows the form in a VS Code panel and debugs the form's code. Clicks, typing and selections in the panel become the form's events (
Click,Change,Enter/Exit,QueryCloseand so on), and breakpoints in the handlers stop there. The ✕ of the panel (or closing the panel's tab) is the form's close button. Errors raised in a handler are shown in the panel and the Debug Console, and the run goes on (to stop on them, enable "Caught Exceptions" in the breakpoints). A form shown withfrmInput.show()from a function of another module is shown in the same kind of panel.
The CodeLens can be hidden with the setting ras.codeLens.run.
Generating tests
Above the exported functions of the modules in src/, a "Generate Test" CodeLens is shown too.
⚙ Debug | 🧪 Generate Test
export function sumTo(n: int): int {
Clicking it adds the skeleton of a test of that function to test/<module>.test.ras (test/report.test.ras for src/report.ras) and opens the line of the test. (The skeleton's names and comments come from the language server, in the display language.)
import { sumTo } from "src/main";
describe("sumTo", () => {
test("return value of sumTo", () => {
// Arrange: replace the values of the arguments
const n: int = 0;
const actual = sumTo(n);
// Assert: replace with the expected value
expect(actual).toBe(0);
});
test.todo("edge values (0, the empty string, the largest value, ...)");
});
- The arguments become constants with type annotations, holding placeholder values that fit their types (
0,"",false,[], a struct literal, the first member of an enum, the first sheet of the workbook forExcel.Worksheet, and so on). Optional arguments are not passed. An extension method (with athisargument) is called liketarget.lastRow(). - The return value is compared with a placeholder value by a matcher that fits its type (
toBefor numbers,toBeCloseTofor floating-point numbers,toEqualfor arrays and structs,not.toBeNothingfor objects). A function without a return value is called, with a comment showing how to check cell values and the like. The placeholder values pass the type check, so the test runs withras testright away. Change the values to what you want to check. - When the test file exists, the function's name is added to its
import(or animportline is added), and the new test goes at the end of thedescribewith the function's name, or in a newdescribeat the end of the file. - The CodeLens can be hidden with the setting
ras.codeLens.generateTest.
With a launch.json, use the configuration type ras.
{
"type": "ras",
"request": "launch",
"name": "RAS: rebuildReport",
"entry": "Report.rebuildReport"
}
| Attribute | Description |
|---|---|
entry |
The function to run (ModuleName.functionName or just the function name). When omitted, it is chosen at start. |
project |
The folder with ras.toml. Defaults to the workspace folder. |
stopOnEntry |
Stops at the first line of the entry point function (in its .ras file). |
dialogs |
What happens when Excel shows a dialog while the program waits for Excel. notify (default: reports the dialog and brings it to the front) / dismiss (reports it and closes it with the button that amounts to Cancel; End for a VBA run-time error) / off. |
excel |
The Excel the program works on. auto (default: Excel on Windows, the Excel stand-in on Mac and Linux) / excel (Excel only) / standIn (the Excel stand-in, on Windows too). Defaults to the setting ras.debug.excel. |
runtimeExecutable / comAddon / bookAddon / mockHost |
Replace the Node.js that runs the program, the addon that connects to Excel, the addon of the Excel stand-in, or the Excel stand-in module (not normally needed). |
Debugging does not run on VBA: the program is converted to JavaScript and run on the runtime that comes with VS Code. What it does to Excel is done to the real Excel, through the bundled addon (ras_com.node, Windows only).
On Mac and Linux, and on Windows without Excel, the program reads the workbook of workbook in ras.toml instead of using Excel, and runs reading and writing its cells (the bundled addon ras_book.node).
Formulas are calculated by the Excel stand-in, and recalculated when cells change, like Excel's automatic calculation.
The workbooks the program changed are saved to
build/debug/workbooks/at the end. The original workbook is not changed.Inserting and deleting cells, cut, copy and paste (within the stand-in only; nothing is exchanged with other applications), sorting and filters are supported.
Formatting such as fonts, colors, borders and column widths is saved in the workbook (there is no screen, so nothing is drawn).
The workbook and sheet events raised by what the program does (
Change,SelectionChange,Activate,BeforeSaveand so on) call the@onhandlers.With manual calculation (
Application.Calculation), formulas are not recalculated untilCalculateis called.Scripting.FileSystemObject,Scripting.DictionaryandVBScript.RegExpcan be used (text files are read and written in Shift_JIS or UTF-16, as on Windows). Other COM objects, such asADODBandWScript.Shell, cannot be created.Operations that need Excel itself, such as hand-written VBA (
Application.Run) and dialogs, raise errors. ARangekept in a variable does not follow inserted and deleted cells, unlike in Excel.What is supported and how it differs from Excel is summarized in §14.10.8 of the language specification.
What can be run is a function without arguments, or the top-level statements. Event handlers (
@on) and UDFs cannot be started.When the workbook is open in Excel, the program connects to it; otherwise the workbook is opened.
There are differences from running in Excel, such as timing and speed, the precision of some numeric types, and VBA built-in functions that are not supported (§14.10.5 of the language specification).
The program's standard output and unhandled errors are shown in RAS Debug in the Output panel. The output of
console.logalso goes to the Debug Console.
Running tests
The tests in test/**/*.test.ras ([test] include in ras.toml changes where) are shown in VS Code's Test Explorer (the flask icon in the Activity Bar), as a tree of test files → describe → test. The list comes from ras test --list, which reads it from the syntax without running the tests. Saving, adding or deleting a .ras file or ras.toml reads the list again.
- Running: ▷ in the Test Explorer runs all the tests, a test file, a
describeor a single test. In the editor of a test file, ▷ is also shown in the gutter next to eachdescribe/test. The command "Test: Run Test at Cursor" works too. - Debugging: "Debug Test" in the Test Explorer or in the gutter's context menu debugs the tests. They stop at breakpoints in the test files and in the
.rasfiles ofsrc/, with variables, watch expressions and stepping. A debug session starts for each test file and closes when its tests have finished. While stopped, the tests do not time out. The results are shown as for a normal run. - Results: passed, failed and skipped tests (
test.skip/test.todoincluded) are marked in the Test Explorer and in the gutter. A failed test shows its message on the line of the failedexpect, and fortoBe/toEqualand the like the difference between the expected and the actual value can be opened. The output ofdebug.printis shown next to the line that printed it and in the Test Results panel. The message also gives where the workbook of a failed test was saved (build/test/workbooks/). - The workbook of a failed test: the [Show the Failed Test's Workbook in Sheet Preview] button of a failed test's message (shown in the editor), the context menu of the message in the Test Results panel, or the context menu of the test in the Test Explorer opens the workbook as it was when the test failed in the sheet preview. The cells changed since the test started (after
beforeAll) are marked, with a list of the changes and what the cells held before. When the test opened other workbooks too, you choose which one to show. "RAS: Show the Failed Test's Workbook in Sheet Preview" in the Command Palette offers the tests with saved workbooks. The workbooks stay untilras testruns again. - As with
ras test, the tests run on the Excel stand-in, without starting Excel (the run target in the status bar does not change that). The Node.js that comes with VS Code is used, so no separate installation is needed. The file that reads and writes workbooks (ras_book.node) is looked for as for debugging: the settingras.debug.bookAddon, the one shipped with the extension, then the folder of therasexecutable. - Unsaved files are saved before running. With compile errors the tests do not run, and the errors are shown as the result of the tests.
- The cases of a
test.eachdecided at run time (whose table is not an array literal) are shown under their template once they have run. - ■ in the Test Results panel stops the run (while debugging, it also ends the tests held at a breakpoint).
Settings
| Setting | Default | Description |
|---|---|---|
ras.path |
"" |
Path of the ras executable. When empty, ras (ras.exe on Windows) is looked up on PATH. A relative path is resolved against the first workspace folder, and a leading ~ is expanded to the home directory. Changing it restarts the language server. |
ras.server.extraArgs |
[] |
Arguments added after ras lsp --stdio when the language server starts. Changing them restarts the language server. |
ras.trace.server |
"off" |
Logs the traffic between VS Code and the language server to "RAS Language Server" in the Output panel (off / messages / verbose). |
ras.codeLens.run |
true |
Shows the "Run in Excel" (Windows only) and "Debug" CodeLens above the functions that can be started on their own. |
ras.run.target |
auto |
Where "Run" runs. auto (excel on Windows, standIn elsewhere) / standIn (the Excel stand-in) / excelCom (Excel over COM) / excel (the VBA in Excel). With standIn and excelCom, debugging runs there too. Switched from the status bar. |
ras.debug.runtimeExecutable |
"" |
Path of the Node.js used for debugging. When empty, the runtime that comes with VS Code is used. |
ras.debug.comAddon |
"" |
Path of the addon that connects to Excel (ras_com.node). When empty, the one shipped with the extension is used, else the one in the folder of ras. |
ras.debug.excel |
auto |
The Excel the program works on while debugging. auto (Excel on Windows, the Excel stand-in elsewhere) / excel / standIn (the stand-in, on Windows too). |
ras.debug.bookAddon |
"" |
Path of the addon of the Excel stand-in (ras_book.node). When empty, the one shipped with the extension is used, else the one in the folder of ras. |
ras.debug.dialogs |
notify |
What happens when Excel shows a dialog and waits for an answer (notify / dismiss / off). Can be overridden per configuration with dialogs in launch.json. |
In RAS files, the semantic highlighting of the language server (editor.semanticHighlighting.enabled) is enabled by default.
Language server features
| Feature | How |
|---|---|
| Completion | Members after ., named arguments (after ( and ,). The exports of other modules that are not imported yet are offered too; accepting one adds the import |
| Quick info, parameter info | Hover. After a function's ( or ,, shows the signature and the argument being entered (with its @param description) |
| Go to definition, go to type definition | F12 / context menu → [Go to Type Definition] |
| Find and highlight references | Shift+F12 ([Find All References] is Shift+Alt+F12). The uses of the name at the cursor are highlighted in the file |
| Rename | F2. Rewrites all references in the project (including imports, named arguments, type annotations, @param, and keys of object literals). Renaming an interface member also renames the members of the same name in the classes that implement it. Renaming to a VBA reserved word, to a name that differs only in case (VBA does not tell them apart), to a name already used in the same scope, or renaming a name declared in type definitions (.d.ras) or a control name of a form is refused, with the reason |
| Symbols | Outline, [Go to Symbol] (Ctrl+Shift+O), [Go to Symbol in Workspace] (Ctrl+T) |
| Inlay hints | Inferred types of variables and lambda parameters, inferred type arguments of generic functions, byref before arguments passed by reference (toggled with editor.inlayHints.enabled) |
| Semantic highlighting | Colors arguments, local variables, properties, methods, Excel / VBA names and more differently. Arguments passed by reference are underlined, and @deprecated declarations are struck through (can be changed with *.byref:ras / *.extension:ras and so on in editor.semanticTokenColorCustomizations) |
| Quick fixes | Change names spelled the VBA way to camelCase; add the import of a name that is not imported. With "editor.codeActionsOnSave": { "source.fixAll": "explicit" }, all names spelled the VBA way are fixed on save |
| Folding | Blocks, multi-line comments, runs of imports, // #region … // #endregion |
| Formatting, CodeLens | "Format Document" (also changes names spelled the VBA way (W0304) to camelCase before formatting; the same fix as ras check --fix), and "Run in Excel", "Debug" and how optimizations were applied above functions |
Live sync with Excel (Windows)
While the workbook set in project.workbook of ras.toml is open in Excel, every time a .ras file or a user form file (forms/*.form.json, forms/*.ras, the pictures in forms/assets/) is saved, the generated VBA and user forms are applied to the VBA project of that workbook (disable with [sync] enabled = false). A workbook opened later is connected to and synced within a few seconds.
- Required setting: In Excel, enable "Trust access to the VBA project object model" under [File] → [Options] → [Trust Center] → [Trust Center Settings] → [Macro Settings].
- What is applied is the saved content. Nothing is synced while there are build errors.
- Rewriting the code resets the global variables of VBA.
- User forms are written into the workbook too. A form whose design changed is imported into the workbook again; for a form whose code (
forms/<name>.ras) alone changed, only the code is rewritten. When the form is still loaded in Excel (only hidden withHide, or shown modeless), or its designer is open in the VBE, the form is closed before writing (events such asQueryCloserun). - While a macro runs, in break mode, while a cell is being edited, or while a dialog is shown, the sync is held back and applied as soon as Excel accepts operations again.
- Modules managed by RAS that were edited in Excel (VBE) (drift) are not overwritten. "Sync with Workbook" lets you choose whether to overwrite them.
- Hand-written standard modules, the code of sheets /
ThisWorkbook, and user forms made in the VBE are converted to RAS and imported into the project (src/,forms/) on sync, and replaced in the workbook by the code RAS generates. Those that still have lines that could not be converted (// TODO(VBA):) are left in the workbook as they are until those lines are fixed ([sync] pull-unmanaged = falsestops the import). - On sync, the module file of each sheet of the workbook and of
ThisWorkbook(objects/Sheet1.ras,objects/ThisWorkbook.ras) is created when it does not exist. The workbook's modules are not changed until you write code in them ([sync] sheet-files = falsestops this). - When the workbook has a module of the same name that RAS did not generate, nothing is written and a warning is shown.
- While the workbook is closed, nothing is applied automatically. Clicking the status bar ("Sync with Workbook") writes straight to the workbook file (the same as
ras pack).
Status bar
The sync status is shown on the left. Clicking it runs "Sync with Workbook" (writing to the workbook file offline when not connected; restarting the language server when it is stopped). On Windows, an [Open in Excel] button is shown to its right while not connected.
| Shown | Meaning |
|---|---|
RAS: Book.xlsm |
Connected to the workbook open in Excel. |
RAS: Not connected |
The workbook is not open in Excel (always shown on systems other than Windows). The tooltip gives the reason. |
| An up arrow and a number | The number of saves not yet applied to the workbook (build errors, Excel busy, and so on; the tooltip gives the reason). |
| A warning icon and a number (warning background) | Drift warnings: modules managed by RAS were edited in Excel (VBE). |
RAS: Stopped |
The language server is not running. |
User form designer
The design of a user form goes in forms/<name>.form.json directly under the project (FormSpec v1: JSON based on the FormSpec of xlflow), and its code, such as the event handling, in RAS in forms/<name>.ras (this is the form and the controls are this.<name>; events are received by functions marked with @on("<control name>.<event>"); completion after this., type checking, hovers and so on work as in the files of src/). The *.form.json files directly in forms/ open in the designer by default (to edit the text, use [Open JSON] or "Reopen Editor With…"). The designer is a port of the UserForm Designer of xlflow.
{
"schemaVersion": 1,
"kind": "ras.userform",
"basis": "designer",
"form": { "name": "OrderForm", "caption": "Order", "width": 240, "height": 180 },
"controls": [
{ "id": "ok", "name": "OkButton", "type": "CommandButton", "caption": "OK", "left": 160, "top": 144, "width": 72, "height": 24 }
]
}
Placing and editing: Choose a kind in the toolbox and click the form (or a Frame, or the page shown) to place a control of the default size, or drag to place it with the size of the rectangle (as in the VBE). Drag to move, resize with the 8 handles (width × height is shown below the control while dragging), and resize the form at its right and bottom edges. The arrow keys move by 1pt, Shift+arrow by 10pt. Showing and snapping to the grid, smart guides, and the zoom (50–200%) are switched in the footer (the settings are kept when the designer is opened again). With smart guides on, a control moved by dragging (with several selected, all of them) snaps to where it lines up with the edges and centers of other controls and the center of the form (Frame, page), to where it has the same spacing as controls in the same row or column or is equally far from both neighbors, and to 8, 16 and 24pt from a neighboring control or the edge of the form, and the guide lines and spacings are shown. An axis that does not snap to a guide follows the grid snap; dragging with Alt held down does not snap. Dragging onto a Frame or a page changes the parent.
Selection and alignment: Select several controls of the same parent with Ctrl / Shift+click or a selection rectangle; the toolbar has the operations of Visual Studio's [Format] menu. The control selected last is the reference.
- [Align]: Lefts, Centers, Rights, Tops, Middles, Bottoms (two or more), to Grid (the top left corner to the nearest grid point; also in the context menu)
- [Make Same Size]: Width, Height, Both (two or more), Size to Grid (the bottom right corner to the grid lines; the position is kept)
- [Spacing]: horizontally and vertically each, Make Equal (three or more; the ends stay), Increase, Decrease (by one grid step), Remove (to 0). The reference control stays and the others move away or closer
- [Center in Form]: moves the selected controls, keeping their arrangement, to the horizontal or vertical center of the parent (form, Frame, page) (one is enough)
- [Order]: Bring to Front, Bring Forward, Send Backward, Send to Back
Operations that would put controls outside their parent are not done. Cut, copy, paste and duplicate (Ctrl+X / C / V / D) and delete (Delete) are supported. Deleting a container with children asks for confirmation.
Anchors: With Anchor (Layout) in [Properties], choose the edges of the parent (form, Frame, MultiPage) a control keeps its distance to when the parent's size changes, by clicking the bars of a cross diagram, as in Visual Studio (written to
anchoras in"top,left,right"; going back to the default Top, Left removesanchor). With both left and right, the width stretches; with both top and bottom, the height; with right (bottom) only, the control moves with the right (bottom) edge; on an axis with neither, it keeps its center. Resizing a form or Frame in the designer moves the controls by their anchors while dragging (it cannot be made smaller than the controls fixed in it). In Excel, the code the build generates moves them the same way inUserForm_Resize(when code changesWidth/Height, or the user resizes a form made resizable through the API; the same in debug runs). Page and ProgressBar have no anchors.Resizing the form: With the form selected, turning on Resizable (
resizable) under Layout in [Properties] lets the user resize the form in Excel by dragging its frame (the code the build generates adds a sizing frame through the Windows API). With MinimumWidth, MinimumHeight, MaximumWidth and MaximumHeight (minimumWidthand so on; the inner size in points, 0 for no limit), the size stays within that range, whether the user resizes the form or code changesWidth/Height. Together with anchors, the controls move and stretch as the form is resized. Resizing the form in the designer stays in the range too, and setting a minimum or maximum that the current size is outside of changes the form's size to it. Forms run for debugging can also be resized by dragging the right edge, the bottom edge or the bottom right corner.Placeholders: With a TextBox selected, text in Placeholder (
placeholder) under Appearance in [Properties] is shown in gray while the box is empty and has no focus (on the canvas too). In Excel it is written as a label over the box: releasing the mouse button over the label hides it so that the box can be edited, and it is shown again when editing ends with the box empty. The mouse pointer over the label is an I-beam. Debug runs behave the same way.Properties: [Properties] in the right pane edits the name, Caption, position and size, Enabled, Tag, ControlTipText and so on. Font and ForeColor / BackColor have their own dialogs. [Structure] lets you select overlapped and hidden controls by name, and [Tab Order] sets the TabIndex of all controls at once. The pages of a MultiPage and the tabs of a TabStrip are added, removed and reordered in the list shown when it is selected.
Pictures: Choosing a file with "Choose Picture…" in the dialog opened by [...] of the Picture of an Image, Label, CommandButton, CheckBox, OptionButton, ToggleButton, Frame, Page or the form writes its path relative to the project root (the folder with
ras.toml; the parent folder offormswhen there is none) intopicture.path. A file inside the project is referred to where it is; a file outside it is copied intoforms/assets/(when a file of the same name with different content is there, a number is added, as inlogo-2.bmp; when a file with the same content is there, that one is referred to). BMP, JPEG, PNG, GIF, WebP, TIFF and ICO files (16 MiB or less) can be chosen. Uncompressed 24 / 32-bit BMPs and JPEGs (16 million pixels or less) are embedded in the form as they are. Other pictures keep the original file andpicture.path, and are converted to 24-bit BMPs when the form is written into the workbook (up to 16 MiB after conversion, about 5.5 million pixels; the first frame of a GIF). Transparent parts get the color of the Image control's BackColor (buttonFace, #F0F0F0, when none is given) blended in. So a converted picture becomes a BMP when imported withras form pull. The format is told from the file's content; an unsupported format or a picture that is too large is an error when chosen (broken picture data is reported at build time). The canvas shows the picture according to PictureSizeMode and PictureAlignment (TIFF cannot be shown, so only the file name is shown). The picture of a Label and the like is shown beside the caption (PicturePosition); that of a Frame, Page or the form as the background (PictureAlignment, PictureSizeMode, PictureTiling). For MouseIcon (the pointer when MousePointer is Custom), choose an icon (.ico) or cursor (.cur) file the same way. Forms run for debugging show these pictures and mouse icons too. "Delete Picture" removespicture(copied files stay informs/assets/even when deleted or undone). When the file ofpicture.pathis missing or cannot be used as a picture, a warning is shown in the [Problems] panel.List items: In the List of a ComboBox / ListBox, enter one item per line (written to
listas an array of strings; leaving it empty removeslist). For items with several columns, separate the columns with tabs (the Tab key enters one, and a range of cells copied from Excel can be pasted as it is;listgets an array of strings per column). ColumnCount, ColumnWidths, BoundColumn, TextColumn and ColumnHeads can also be set in [Properties], and the canvas and forms run for debugging show the columns and the header row. In SelectedIndex (selectedIndex), give the number of the item selected first, counting from 0; -1 for none. Only the numbers of the items inlistcan be given, and only -1 when there is nolist. When the List loses items and the selected number falls out of range, SelectedIndex goes back to -1. The items and the selection are set by the code the build generates when the form is initialized (UserForm_Initialize). On the canvas, a ListBox shows its items and a ComboBox its selected item. The Style (DropDownCombo / DropDownList), ShowDropButtonWhen and ListRows of a ComboBox, the MultiSelect of a ListBox, and the ListStyle and MatchEntry of both can also be chosen in [Properties]. With a range of cells in RowSource (rowSource, e.g.Sheet1!A2:A10), the items are read from those cells when the form opens (it cannot be given together with List; the canvas shows the range). The ControlSource (controlSource) of a control with a value is the cell the value is linked to. Forms run for debugging also read these cells from Excel and write the confirmed values to the ControlSource.Control properties: VBA properties with a single value, such as Locked, MultiLine, PasswordChar, WordWrap, AutoSize, BackStyle, SpecialEffect, BorderColor, Alignment, the TripleState of a CheckBox / OptionButton / ToggleButton, the Default, Cancel and TakeFocusOnClick of a CommandButton, the Min, Max, SmallChange, LargeChange and Orientation of a SpinButton / ScrollBar, the Style, TabOrientation and MultiRow of a TabStrip / MultiPage, TabStop, MousePointer and IMEMode, can be set in [Properties] (the choices are shown by the names of the VBA constants). What is not given gets the value Excel gives a new control, except that Label, CheckBox and OptionButton made from the [Toolbox] get BackStyle fmBackStyleTransparent, so that their background follows the BackColor of the form or frame. A new form gets the system UI font (Windows' SystemFonts.MenuFont: Yu Gothic UI on Japanese Windows 10 and later) at 10pt as its Font. Controls made from the [Toolbox] take over the form's Font, or this font when the form has none (not MSForms' default, MS UI Gothic 9pt). The canvas and forms run for debugging reflect SpecialEffect, BackStyle, Alignment, PasswordChar, the drop button, the Style and TabOrientation of tabs (the text of left and right tabs is rotated to vertical) and so on.
Value of a CheckBox / OptionButton / ToggleButton: Choose from True, False and Null (Null is written as
"Null"). Null is shown as on Windows, with a gray mark in a shaded box. In forms run for debugging, a CheckBox / ToggleButton with TripleState True goes False → Null → True → False with each click (TripleState has no effect on an OptionButton).Form properties: [Properties] with the form selected sets StartUpPosition, ShowModal, Tag, Enabled, BorderColor, SpecialEffect, Cycle, MousePointer, Zoom, ScrollBars, KeepScrollBarsVisible, ScrollWidth / ScrollHeight / ScrollLeft / ScrollTop, HelpContextID, WhatsThisButton / WhatsThisHelp, RightToLeft and DrawBuffer (written to
form). The canvas reflects the form's border (BorderStyle, BorderColor, SpecialEffect); forms run for debugging also reflect Zoom, scrolling and the mouse pointer.Height of a TextBox: When a single-line TextBox / ComboBox is lower than one line of its font, Excel cuts off the text and leaves a line at the edge. When the font or its size is changed in the designer, a missing height is added automatically. Controls written too low directly in JSON get a warning (
UFV022) in the [Problems] panel.Border and special effect: MSForms cannot draw a border with BorderStyle Single and a SpecialEffect (3D) at the same time; in the VBE too, setting one resets the other. When both are given, a warning (
UFV023) is shown in the [Problems] panel and the border wins when writing into the workbook (SpecialEffect is made flat).Events: Double-clicking a control or the background of the form opens the handler of the default event (
Clickfor a CommandButton,Changefor a TextBox,UserForm_Clickfor the form), a function marked with@on("OkButton.Click"), informs/<name>.ras. When there is none, an empty handler is added with the arguments of the event (cancel: MSForms.ReturnBooleanand so on). [Open Event…] in the context menu lets you choose other events.Problems: The [Problems] panel at the bottom shows the results of validating the FormSpec (duplicate IDs, missing parents, properties that do not fit the kind, and so on); choosing one shows the item in the JSON. Edits that would cause new validation errors are not applied.
Undo and save: Everything done in the designer is an edit of the JSON document, so VS Code's undo / redo, save and auto save work as they are. Editing the JSON in a text editor shows up in the designer right away.
Forms made in the VBE can be imported into forms/ with the CLI's ras form pull [name…] [--book <file>] [--force] (it writes forms/<name>.form.json and forms/<name>.ras, and the pictures to forms/assets/; the code is converted from VBA to RAS, and lines that could not be converted are left as // TODO(VBA): comments). FormSpecs in YAML are not supported.
Restricted Mode (untrusted workspaces)
In an untrusted workspace, only syntax highlighting is available. The language server and the Test Explorer become available when the workspace is trusted.
Development
npm ci
npm run compile # type check (tsc --noEmit) and bundling with esbuild
npm test # tests of the TextMate grammar and the user form designer
npm run package # creates ras-vscode-<version>.vsix
Node.js 22 or later is needed. syntaxes/ras.tmLanguage.json is generated by scripts/build-grammar.mjs. The designer's UI (webview/userFormDesigner/) is bundled into dist/webview/ by esbuild. Do not edit generated files directly; change the script and run npm run build:grammar.
The texts of package.json (command titles, settings and so on) are in package.nls.json (English, the default) and package.nls.ja.json (Japanese). The messages of the extension are written as t("日本語", "English") (src/l10n.ts).
License
MIT License. For the third-party works this extension includes (the TextMate grammar of TypeScript, the user form designer of xlflow, and others), see THIRD_PARTY_NOTICES.md.