sodcalculator

10 Tech How-To

Remove Macros & Inspect VBA Code in Excel Safely

Guide 10-20674 · Updated · Step by step

This guide shows you how to remove macros from an Excel workbook and safely inspect the VBA code before opening or sharing the file. You’ll learn how to view macros without executing them, delete them permanently, and avoid common pitfalls that can leave hidden code behind. By the end, you’ll be able to clean a workbook and verify it’s macro-free.

What You’ll Need

  • A Windows PC with Microsoft Excel (2016 or later, or Microsoft 365). Mac steps are similar but menu names may differ slightly.
  • The Excel file you want to clean. If it’s a .xlsm or .xlsb file, macros are likely present. A .xlsx file may still contain macros if they were added later, but usually not.
  • A backup copy of the original file. Always work on a copy until you’re sure the macros are gone.
  • Basic familiarity with Excel’s ribbon and file menu.

Step-by-Step

  1. Back up your file. Copy the original workbook to a safe folder. This is your recovery point if something goes wrong.
  2. Open Excel, but do NOT double-click the file. Launch Excel first (from Start menu or taskbar). Then use File → Open to browse to the file. This gives you more control before any code runs.
  3. Disable macros before opening. When the file opens, Excel may show a yellow bar with “Enable Content.” Do not click it. If you see a security warning, choose “Enable Editing” only if you trust the file; for inspection, leave macros disabled. To be extra safe, go to File → Options → Trust Center → Trust Center Settings → Macro Settings and select “Disable all macros without notification.” This prevents any macro from running automatically.
  4. Open the Visual Basic Editor (VBE). With the workbook open (macros disabled), press Alt + F11 on Windows, or Option + F11 on Mac. This opens the VBA editor without running any code.
  5. Inspect the Project Explorer. In the VBE, look at the left panel (Project Explorer). If you don’t see it, press Ctrl + R (Windows) or Cmd + R (Mac). Expand the project tree for your workbook. You’ll see folders like Microsoft Excel Objects (for sheets and ThisWorkbook), Modules, Class Modules, and UserForms.
  6. View the code. Double-click each item under Modules, Class Modules, and UserForms to see the code in the right pane. For sheet objects (like Sheet1), double-click them to see any event code (e.g., Worksheet_Change). For ThisWorkbook, check for Workbook_Open or Workbook_BeforeClose events.
  7. Identify all macros. In the VBE, go to View → Project Explorer (if not already open). Then click Insert → Module to see if there are any empty modules. To list all macros, press Alt + F8 in Excel (not VBE) to open the Macro dialog. This shows all macros in the workbook. Note the names and locations.
  8. Remove macros manually (if you want to keep the workbook as .xlsm). In the VBE, right-click on each module, class module, or userform in the Project Explorer and choose Remove Module. When prompted, click “No” to avoid exporting the code. For sheet objects and ThisWorkbook, delete the code in the right pane by selecting all (Ctrl+A) and pressing Delete. Be aware that removing a module deletes all code in it.
  9. Remove macros by saving as .xlsx. The cleanest method: close the VBE and go to File → Save As. Choose “Excel Workbook (*.xlsx)” as the file type. Excel will warn that macros will be removed. Click “Yes” to confirm. This creates a new file without any VBA code. The original .xlsm file remains untouched.
  10. Verify the macros are gone. After saving as .xlsx, close the file and reopen it. Press Alt + F8 – the Macro dialog should be empty. Also press Alt + F11 to open the VBE; the Project Explorer should show only sheet objects and ThisWorkbook, with no code in them.
  11. Check for hidden macros in add-ins or personal workbook. If you still see macros after cleaning, they might be in your Personal Macro Workbook (PERSONAL.XLSB) or an add-in. Go to File → Options → Add-ins and manage COM add-ins and Excel Add-ins. Disable any suspicious add-ins. Also check if the file is linked to external references that contain code.
  12. Use a third-party tool (optional). If you need to inspect many files, you can use a VBA code cleaner or a file inspection tool. But for most cases, the manual steps above are sufficient.

Common Mistakes

  • Clicking “Enable Content” too soon. If you enable macros, any code in the workbook runs immediately, potentially executing harmful actions. Always keep macros disabled until you’ve inspected the code.
  • Forgetting to check sheet and ThisWorkbook code. Macros aren’t only in modules; they can be in worksheet events (like Worksheet_Change) or workbook events (Workbook_Open). These can run automatically.
  • Deleting modules without saving a backup. Once you remove a module, you can’t undo it. Always keep the original file.
  • Saving as .xlsx but still seeing macros. If you save as .xlsx, macros should be stripped. But if the file has a digital signature or is protected, the process might fail. Also, if you have macros in the Personal Workbook, they won’t be removed.
  • Not closing other workbooks. When you press Alt+F8, you might see macros from other open workbooks. Make sure you’re looking at the correct file.

Tips

  • Use the “Disable all macros without notification” setting when inspecting untrusted files. You can re-enable later.
  • Export a copy of the VBA code before deleting it, if you might need it later. In the VBE, right-click the module and select “Export File.” Save as .bas or .frm.
  • If you only want to remove macros but keep the .xlsm format, you can delete all modules and code, then save. But saving as .xlsx is simpler and more reliable.
  • Check the file extension. A file named .xlsx shouldn’t contain macros. If it does, it’s been tampered with – be extra cautious.
  • Use a text editor to peek inside the file (if you’re comfortable). Rename the file to .zip, extract, and look at the “vbaProject.bin” file. If it exists, macros are present. But this is advanced; the VBE method is easier.

Troubleshooting

I can’t see the Project Explorer in VBE. Press Ctrl+R (or Cmd+R on Mac) to show it. If it’s still missing, go to View → Project Explorer.

The Macro dialog (Alt+F8) is grayed out. This happens if the workbook is protected or shared. Unprotect the workbook (Review → Unprotect Workbook) and try again.

I saved as .xlsx but the file still has macros. This can occur if the workbook is password-protected for structure. Save a copy without protection first. Also, check if macros are in the Personal Workbook – those are stored separately and won’t be removed.

I see “Cannot edit macro” or “Macros are disabled.” Go to Trust Center Settings and enable “Trust access to the VBA project object model” if you need to edit code. But for inspection, you don’t need this.

The VBE opens but no code appears. The workbook might have no macros. That’s fine – you’re done.

Frequently Asked Questions

Can I remove macros without opening the file?

Yes, you can use a command-line tool or a script to strip VBA, but the safest and easiest way is to open the file with macros disabled and remove them manually.

Will saving as .xlsx remove all VBA code?

Yes, the .xlsx format does not support macros, so Excel strips all VBA code when you save as .xlsx. However, make sure you don’t have external references to other macro files.

How do I know if a workbook has macros before opening it?

Check the file extension: .xlsm, .xlsb, or .xls (older) may contain macros. .xlsx and .xlsm are the most common. You can also right-click the file, go to Properties, and look at the file type.

Can macros run if I open the file with macros disabled?

No, if you disable macros, Excel won’t execute any VBA code when the file opens. However, some events like Workbook_Open might still trigger if you click “Enable Content” – so don’t click it.

Is it safe to delete modules in VBE?

Yes, you can delete modules, but make sure you have a backup. Once deleted, the code is gone permanently unless you exported it.

What if I need to keep some macros but remove others?

You can manually delete specific modules or code blocks. Right-click the module in Project Explorer and choose “Remove Module,” or delete the code in the editor. Keep the ones you need.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →