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

  1. Work on a copy. Upload the .xlsm to Google Drive and open it as a Google Sheet. Keep the Excel original untouched as the reference for testing.
  2. 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.
  3. 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 VBAIn Apps Script
ThisWorkbook, Worksheets("Data"), Range("A1")SpreadsheetApp.getActiveSpreadsheet(), .getSheetByName('Data'), .getRange('A1') (SpreadsheetApp)
Range("A1").Value = xrange.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, InputBoxSpreadsheetApp.getUi().alert() and .prompt() (Ui)
A UserFormNo 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 dialogA custom menu built in onOpen(), or a Sheets macro with a keyboard shortcut
Workbook_OpenThe onOpen(e) simple trigger
Worksheet_ChangeThe onEdit(e) simple trigger, with limits (below)
Application.OnTimeA time-driven installable trigger
Sending mail through OutlookMailApp or GmailApp, which ask the user to authorise the script once
Dir, FileSystemObject, Open ... For OutputFiles live in Google Drive, through DriveApp. A script cannot see the C: drive.
ADO / ODBC to a databaseThe 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 = FalseNot needed; there is no screen to update while a script runs

Where the behaviour changes

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.

More guides