No. Google Sheets cannot run VBA macros: VBA is Microsoft Excel’s programming language, and Sheets uses Google Apps Script for spreadsheet automation. To automate a task in Sheets, record a macro or recreate the workflow in Apps Script rather than trying to run the original VBA code.
What VBA macros are—and why Sheets cannot run them
VBA, short for Visual Basic for Applications, is built into desktop Microsoft Office applications such as Excel. An Excel macro can contain VBA instructions that manipulate cells, worksheets, charts, files, and other Office features. Google Sheets is a separate web-based spreadsheet product, so it does not include Excel’s VBA environment or the tools that execute VBA code.
That distinction matters when you open an Excel workbook in Sheets. A workbook may contain macro-enabled VBA code, often stored in an .xlsm file, but Sheets does not execute that code. Converting an Excel workbook to Google Sheets does not turn its VBA into a working Sheets macro. The data and many ordinary spreadsheet features may transfer, but macro automation needs a different solution.
Changing a file extension or copying VBA code into the Apps Script editor will not make it work. VBA and Apps Script have different languages, objects, and ways of interacting with a spreadsheet. A task may be straightforward to reproduce, but the original code usually needs to be rewritten or replaced.
What Google Sheets uses instead
Google Apps Script is the main built-in option for writing custom automation in Google Sheets. It is based on JavaScript and includes services for working with Google products, including Sheets. A script can read and update spreadsheet ranges, create menus, respond to certain events, or connect to other services, subject to permissions and service limits.
For simple repeated actions, you may not need to write code. Google Sheets includes a macro recorder that captures supported actions and saves them as an Apps Script function. That function can then be run again from the Sheets interface. The recorder is a practical bridge for basic formatting and editing routines, but it is not a VBA translator and does not capture every possible task.
Other options include built-in Sheets features, such as formulas, filters, and conditional formatting, or an add-on designed for a specific workflow. Choosing the simplest tool that meets the need is often easier to maintain than building a large script for something Sheets can already do.
How to record a macro in Google Sheets
In Google Sheets in a web browser, open the spreadsheet and choose Extensions > Macros > Record macro. Carry out the actions you want to repeat, then use the recorder controls to save the macro. Sheets offers relative and absolute reference behavior: relative references apply actions in relation to the selected cell, while absolute references repeat them at the same cell locations. Choose based on how you expect to reuse the routine.
- Open the correct spreadsheet and select a cell if the task depends on a starting position.
- Choose Extensions > Macros > Record macro.
- Choose relative or absolute references, then perform the actions the recorder supports.
- Finish recording, give the macro a name, and save it. You can also assign an available keyboard shortcut during setup.
- Run it later from Extensions > Macros and select the saved macro.
For example, a recorded routine might apply a number format, set a header’s background color, and bold its text. If the steps depend on a particular range, an absolute recording may repeat those same cell locations; a relative recording can be more useful when applying similar actions to another selected area. Try a new macro on a copy of the sheet or a small test range first, especially if it changes many cells.
Writing or editing an Apps Script
To inspect or edit the script associated with a spreadsheet, choose Extensions > Apps Script. The Apps Script editor opens in a browser tab. A recorded macro appears as script code, which gives you a starting point for adjustments that the recorder cannot express. You can also create a script function directly in the editor and run it from there or connect it to the spreadsheet as appropriate.
Imagine a team repeatedly preparing a weekly report. A recorded macro might handle consistent formatting, while a custom Apps Script could apply logic such as checking a status column and acting only on rows that meet a condition. The latter requires code and careful testing; it is not an automatic feature of recording. For complex workflows, break the job into small functions and test each one on sample data before relying on it in a live spreadsheet.
Apps Script may request authorization when a script uses Google services or accesses data. Review the requested permissions and confirm that the script comes from a source you trust before granting access. A script’s presence in a spreadsheet does not by itself mean it is safe or appropriate to run.
How to move an Excel VBA workflow to Sheets
There is no one-click, reliable conversion from VBA to Apps Script. Start by describing what the macro accomplishes in plain language, then identify its inputs, outputs, and dependencies. For example, note which sheet and columns it reads, what conditions it checks, what it changes, and whether it interacts with files, email, or other Office applications.
- Separate spreadsheet work from application-specific work. Reading a range and changing cell formatting may have a Sheets equivalent. Automating an Excel dialog or another desktop Office program may require a different approach.
- Check for existing Sheets features. A filter, conditional formatting rule, data validation, or formula may replace some or all of a macro.
- Rebuild the remaining logic. Use the macro recorder for supported repetitive actions and Apps Script for custom behavior.
- Test against known examples. Compare the output with what the Excel macro produced, including blank cells, unusual values, and error cases.
- Keep the original workbook. If the VBA version is still needed in Excel, retain a separate copy of the macro-enabled file rather than treating a Sheets conversion as a substitute.
Consider a VBA routine that highlights overdue invoices. The underlying rule might be expressible with conditional formatting, avoiding a macro altogether. If the routine also sends notifications or updates several sheets, Apps Script may be more appropriate, but those extra actions must be designed and authorized separately. Translating the business rule is more useful than trying to translate VBA line by line.
Choosing between a macro, Apps Script, and other options
Use the macro recorder when the task consists mainly of repeatable actions that Sheets can record, such as applying formatting or making a predictable sequence of edits. It is a good fit when you want to save time without learning much code. It is less suitable when the workflow depends on complex branching, dynamic data, external services, or detailed error handling.
Use Apps Script when you need custom logic, a user menu, or automation that goes beyond the recorder. It provides flexibility, but it also creates code that someone should understand and maintain. If the task is a one-time cleanup, doing it manually may be safer and quicker than building a script. If it is a recurring data problem, a formula or built-in Sheets feature may be more transparent to colleagues.
Keep the work in Excel if the workflow depends on VBA, desktop Excel features, or other Office automation that Sheets cannot reproduce. In particular, do not assume that switching a workbook to the Google Sheets format preserves its VBA behavior. Teams that share files across Excel and Sheets should agree which application is the authoritative version and test important formatting and functionality after any conversion.
Limitations, permissions, and safe use
Apps Script is not unlimited. Scripts run under Google’s service rules and quotas, and permissions depend on what the code accesses. A simple macro that edits the current spreadsheet is different from a script that reads other files or sends email. A script may prompt for authorization, and some automated behaviors require trigger setup. Check Google’s current Apps Script documentation for applicable limits because they can depend on the service and account.
Be cautious with scripts copied from websites or shared by someone you do not know. Read the code where possible, check what permissions it requests, and avoid granting access that does not match the task. For shared spreadsheets, consider who can edit the file and its associated script. Test changes using a copy, particularly before a script overwrites data or acts on a large range.
Also plan for maintenance. A script that depends on fixed sheet names or column positions may stop behaving as expected after someone reorganizes the workbook. Clear names, documented assumptions, and a small test dataset make automation easier to review and repair. Keep a manual process or backup plan for important recurring work.
Frequently Asked Questions
Can I run an Excel VBA macro in Google Sheets?
No. Google Sheets does not execute VBA. You need to keep the workbook in an Excel environment that supports its macro, or replace the workflow with a Sheets feature or Apps Script.
Does Google Sheets convert VBA to Apps Script?
No. There is no built-in VBA-to-Apps-Script conversion that makes an Excel macro work automatically. The logic needs to be reviewed and recreated using suitable Sheets tools.
Can I open an .xlsm file in Google Sheets?
You can work with Excel files through Google’s file and conversion options, but opening or converting a macro-enabled workbook does not make its VBA run in Sheets. Keep the original .xlsm file if you need its Excel macros.
How do I create a macro in Google Sheets?
In a browser, choose Extensions > Macros > Record macro, perform supported actions, and save the recording. You can later run it from the same Macros menu.
Is Google Apps Script the same as VBA?
No. Apps Script is based on JavaScript and is designed to work with Google services; VBA is used in Microsoft Office applications. They can sometimes accomplish similar tasks, but their code and APIs are not interchangeable.
Can Google Sheets macros run automatically?
Some automation can be set up with Apps Script triggers, but a recorded macro does not automatically run whenever you want without appropriate setup. Trigger types, permissions, and limits depend on the task, so verify the requirements before relying on unattended automation.
Related
- Word: Make One Page Landscape Without Changing Others
- Double Space in Word: Easy Steps for Desktop and Web
- IFS Syntax in Google Sheets: Examples and Common Errors
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Loop Through a Range: Examples and Best PracticesTo loop through cells in Excel VBA, use For Each cell In worksheet.Range("A1:A10").Cells and place the action you…
- Read a Text File with Excel VBA: Methods and ExamplesYes. In Excel for Microsoft 365 on Windows, VBA can read a plain-text file with the Open and…
- Excel VBA: How to Check AutoFilter StatusIn Excel VBA, check Worksheet.FilterMode to find out whether a worksheet currently has a filter applied, and check…
- VBA Range Select: Examples, Uses, and Safer AlternativesIn Excel VBA, use Range.Select to select cells, but the worksheet containing the range must be active first.…
- VBA Array Cheat Sheet: Syntax, Bounds, and ExamplesA VBA array stores multiple values under one variable name, and the essential pattern is to declare it,…
- Excel VBA Copy Worksheet: Code, Methods, and SafetyTo copy a worksheet with Excel VBA, call the worksheet’s Copy method and specify where the duplicate should…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.