Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Save as VBA Excel: How to Save Macro-Enabled Workbooks

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To save a file with VBA (Visual Basic for Applications) code, you must change the file extension from a standard workbook (.xlsx) to a Macro-Enabled Workbook (.xlsm) or a Binary Workbook (.xlsb) via the Save As menu. If you save a file containing macros as a standard .xlsx file, Excel will permanently strip all your code from the document upon saving, and it cannot be recovered.

What You'll Need

  • A computer with Microsoft Excel installed.
  • An existing Excel workbook containing VBA modules, user forms, or worksheet-level code.
  • Administrative permissions to save files to your chosen local or network directory.

Step-by-Step

  1. Open the Excel workbook that contains the VBA code you wish to preserve. (Note: Menu labels may differ slightly depending on your version of Excel or region).
  2. Click on the File tab in the top-left corner of the ribbon to enter the Backstage view.
  3. Select Save As from the left-hand navigation menu. If you are using a version of Excel that defaults to cloud saving, you may need to click Browse or This PC to open the traditional Windows Explorer save dialog box.
  4. In the Save As dialog box, first navigate to the folder where you want to store the file.
  5. Click the dropdown menu labeled Save as type: (located directly below the File name field).
  6. Scroll through the list and select Excel Macro-Enabled Workbook (*.xlsm). This is the most common format for files containing VBA. Alternatively, you can choose Excel Binary Workbook (*.xlsb), which is often faster for very large datasets containing complex macros.
  7. Enter a descriptive name for your file in the File name box.
  8. Click the Save button.
  9. If a warning dialog appears stating that "the following features cannot be saved in macro-free workbooks," ensure you have selected the .xlsm format. If you see this warning and you did select .xlsm, it may be a glitch; however, if you see it while .xlsx is selected, click No to return to the Save As menu and change the file type.

Common Mistakes

The most frequent mistake users make is ignoring the warning prompt when saving. When Excel detects VBA code in a workbook being saved as a .xlsx file, it triggers a pop-up warning. Many users instinctively click "Yes" to proceed, thinking the warning is just a notification. In reality, clicking "Yes" tells Excel to delete every single line of VBA code in the workbook to make it compatible with the macro-free format. Once the file is saved and closed, that code is gone forever unless you have a separate backup.

Another common error is saving the file to a cloud location (like OneDrive or SharePoint) without verifying that the cloud version supports the .xlsm extension. While modern versions of Office 365 handle this well, some older synchronization tools or third-party cloud drives may struggle with macro-enabled files, leading to "read-only" errors or corrupted files when multiple users attempt to access the VBA project simultaneously.

Users also frequently confuse the Save command with the Save As command. If you started with a .xlsx file, added code, and simply hit the Save icon (Ctrl + S), Excel will force the "Save As" dialog because it knows it cannot save the code in the current format. Attempting to bypass this or forcing a save via a script can lead to the loss of the VBA project.

Tips

For those working with massive amounts of data and complex VBA scripts, the Excel Binary Workbook (.xlsb) format is highly recommended. Unlike the .xlsm format, which is based on XML, the .xlsb format stores data in binary. This results in smaller file sizes and significantly faster opening and saving times. It fully supports VBA macros and is often the professional choice for high-performance spreadsheets.

To ensure your macros run smoothly for other users, always create a "Readme" sheet as the first tab of your workbook. Explain that the file must be saved as an .xlsm and that the user must "Enable Content" via the yellow security bar at the top of the screen when they first open the file. Without enabling content, the VBA code will remain dormant and the buttons or automated functions will not work.

It is also a best practice to maintain a separate backup of your code. You can do this by exporting your VBA modules. In the Visual Basic Editor (Alt + F11), right-click a module in the Project Explorer and select Export File.... This saves the code as a .bas file. If your .xlsm file ever becomes corrupted, you can simply import these .bas files back into a fresh workbook.

Troubleshooting

If you have saved your file as an .xlsm but your macros are still not running, check the Macro Security settings. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Ensure that "Disable all macros with notification" is selected. This allows you to choose whether to run macros on a case-by-case basis via the security warning bar.

If you receive an error stating that the file is "blocked" because it originated from another computer or the internet, this is a Windows security feature. Close Excel, right-click the .xlsm file in your folder, select Properties, and look for a checkbox at the bottom of the General tab that says Unblock. Check that box and click OK.

If the file refuses to save as an .xlsm and keeps reverting to .xlsx, check if you have any third-party add-ins installed that enforce "macro-free" policies. Some corporate IT environments use Group Policy Objects (GPO) to prevent the creation of macro-enabled files to protect against malware. If the .xlsm option is greyed out or fails to save, contact your IT administrator to see if macro-enabled workbooks are permitted on your network.

In the event that you accidentally saved as .xlsx and lost your code, immediately check for an "AutoRecover" version. Go to File > Info > Manage Workbook > Recover Unsaved Workbooks. While this is not a guaranteed fix for the .xlsx conversion loss, it is the only internal Excel method for attempting to retrieve a previous state of the document.

Frequently Asked Questions

Can I convert a .xlsx file to .xlsm after I have added code?

Yes, as long as you have not yet saved and closed the file. Use the Save As menu to change the extension to .xlsm before closing the workbook to ensure the code is preserved.

What is the difference between .xlsm and .xlsb?

.xlsm is a standard macro-enabled workbook using XML structure. .xlsb is a binary workbook that also supports macros but is generally smaller and faster to load for large files.

Why does Excel show a security warning when I open my VBA file?

Excel disables macros by default to prevent malicious code from running automatically. You must click "Enable Content" to allow your VBA scripts to execute.

Will my VBA code work on Excel for Mac?

Most VBA code works on Mac, but some Windows-specific commands (like those calling API functions or specific file paths) will fail. You must still save the file as .xlsm on a Mac.

Can I save a VBA project as a PDF?

You can save the results of your spreadsheet as a PDF, but the VBA code itself cannot be "saved" into a PDF. The code only lives within the .xlsm, .xlsb, or .xls file formats.

Does saving as .xlsm make the file larger?

The addition of VBA code adds a small amount of data to the file, but the difference is usually negligible. The file size is primarily driven by the data and formatting in the sheets, not the code itself.