How to convert Excel VBA macros to Google Apps Script
Published 25 October 2026. Checked against Google's documentation on 11 October 2026.
There is no switch that turns VBA into Apps Script. The two languages differ (VBA is Visual Basic, Apps Script is JavaScript on the V8 runtime), and so do the objects they drive: Excel's object model on a PC against Google's services on Google's servers. Converting a macro means rewriting it against the second. This page maps the parts of VBA that most workbooks use onto their Apps Script equivalents, and says where there is none.
Before you start
- Work on a copy. Upload the
.xlsmto Google Drive and open it as a Google Sheet. Keep the Excel original untouched as the reference for testing. - List what the macros do. Note each macro, what triggers it (a button, opening the file, editing a cell) and what it touches outside the workbook: email, files on the PC, a database, another Office program. The outside connections decide how hard the job is.
- Open the script editor. In the Google Sheet, choose Extensions > Apps Script. A script created there is bound to that spreadsheet.
The common pieces, VBA to Apps Script
| In VBA | In Apps Script |
|---|---|
ThisWorkbook, Worksheets("Data"), Range("A1") | SpreadsheetApp.getActiveSpreadsheet(), .getSheetByName('Data'), .getRange('A1') (SpreadsheetApp) |
Range("A1").Value = x | range.setValue(x); for many cells, getValues() and setValues() on a two-dimensional array |
A For loop over Cells(i, 1) | Read the whole range once, loop over the array, write it back once. Google's best practices call alternating reads and writes "slow"; in Excel the cell-by-cell loop was free. |
MsgBox, InputBox | SpreadsheetApp.getUi().alert() and .prompt() (Ui) |
| A UserForm | No direct equivalent. Rebuilt as an HTML dialog or sidebar with the HTML service (dialogs and sidebars). See converting a UserForm. |
| A button or the Macros dialog | A custom menu built in onOpen(), or a Sheets macro with a keyboard shortcut |
Workbook_Open | The onOpen(e) simple trigger |
Worksheet_Change | The onEdit(e) simple trigger, with limits (below) |
Application.OnTime | A time-driven installable trigger |
| Sending mail through Outlook | MailApp or GmailApp, which ask the user to authorise the script once |
Dir, FileSystemObject, Open ... For Output | Files live in Google Drive, through DriveApp. A script cannot see the C: drive. |
| ADO / ODBC to a database | The JDBC service, which supports Google Cloud SQL for MySQL, MySQL, Microsoft SQL Server, Oracle and PostgreSQL. The database must accept connections from Google's servers, so one that only exists on your office network is out of reach. |
Application.ScreenUpdating = False | Not needed; there is no screen to update while a script runs |
Where the behaviour changes
- Triggers are stricter. Google's trigger documentation says simple triggers cannot use services that need authorisation (a simple
onEditcannot send an email), cannot run for longer than 30 seconds, and do not fire when a script edits a cell, only when a person does. An installable trigger lifts the authorisation limit. - Every run has a time limit. A script execution stops after 6 minutes (quotas). A macro that grinds through a large sheet cell by cell in Excel needs the batched rewrite above to fit.
- Arrays and indexes. VBA arrays often start at 1 (and
Option Base 1makes them all do so); JavaScript arrays start at 0, and the arraysgetValues()returns start at 0 while row and column numbers ingetRange(row, column)start at 1. Off-by-one errors are the most common bug in a hand conversion. - Errors.
On Error Resume NextandOn Error GoTobecometry/catch, which does not resume at the next line. Each one has to be rethought, not translated.
Test against the original
Run each converted macro on a copy of real data and compare the result with what the Excel workbook produces from the same data. Test the triggers by actually opening and editing the sheet, because a trigger that works when you run it from the editor can still fail under the limits above.
Know the size of the job first
Most of the effort is in a few places: UserForms, anything outside the workbook, and code that relies on Excel-only behaviour. In MacroBridge's scan of 1,340 macro workbooks from 988 public GitHub repositories (October 2026), the converter could translate every procedure with nothing left out in 6.7% of them. Public code over-represents developers' tools, so treat that as a sample, not a forecast for your file; the point is that a report for your own workbook is worth more than any average.
Sources
Google's documentation, read on 11 October 2026. Google updates these pages; if one now says something different, it wins.
- V8 runtime overview
- SpreadsheetApp reference
- Best practices: use batch operations
- Custom menus
- Simple triggers
- Installable triggers
- Ui class reference (alert, prompt)
- Dialogs and sidebars in Google Workspace documents
- HTML service
- MailApp reference
- DriveApp reference
- JDBC service
- Quotas for Google services
- Google Sheets macros