Where Are Excel Macros Stored? Find VBA Code Locations
In this article
Excel macros are stored within the specific workbook file in which they were created, or in a special global add-in called the Personal Macro Workbook. By default, when you record a macro, it is saved inside the active .xlsx or .xlsm file under its own module. However, if you choose to store it in "Personal Macro Workbook," it is saved in a hidden file named PERSONAL.XLSB located in your Excel startup folder. This allows the macro to be available in any workbook you open on that computer.
What You'll Need
- A copy of Microsoft Excel installed on your computer (Windows or Mac).
- Access to the Developer tab or Visual Basic Editor (VBE) in Excel.
- File Explorer (Windows) or Finder (Mac) access to locate system folders.
- Knowledge of whether your macro was recorded for a single workbook or globally.
Step-by-Step
- Determine the Scope of Your Macro: First, identify where the macro was intended to live. If you recorded it while working in a specific file and selected "Workbook" as the storage location, it is embedded in that file. If you selected "Personal Macro Workbook," it is in a separate hidden file. If you are unsure, proceed to check both locations using the steps below.
- Check the Active Workbook: Open the Excel file where you believe the macro resides. Press
Alt + F11(Windows) orFn + Option + F11(Mac) to open the Visual Basic for Applications (VBA) editor. In the Project Explorer pane on the left, look for the name of your current workbook. Expand the "Modules" folder beneath it. Double-click any module listed there to view the code. If your macro appears here, it is stored directly in this file. - Locate the Personal Macro Workbook: If the code is not in the active workbook, check the global storage. In the VBA editor's Project Explorer, look for a project named "VBAProject (PERSONAL.XLSB)." If you see this project, expand its Modules folder. The code found here is stored in the Personal Macro Workbook, which loads automatically whenever Excel starts.
- Find the Physical File Location (Windows): To find the actual file path of the Personal Macro Workbook, close all instances of Excel. Press
Windows Key + Rto open the Run dialog. Type%appdata%\Microsoft\Excel\XLSTARTand press Enter. A File Explorer window will open showing the contents of the XLSTART folder. Look for a file namedPERSONAL.XLSB. This is the physical file where your global macros are stored. - Find the Physical File Location (Mac): On macOS, the location varies slightly by version. Generally, navigate to
~/Library/Group Containers/UBF8T346G9.Office/User Content/Startup/Excel. You can access this by opening Finder, pressingCommand + Shift + G, and pasting the path. Look forPERSONAL.XLSBin this directory. - Verify Add-ins Storage: Sometimes macros are stored in Excel Add-ins (.xlam files). In Excel, go to File > Options > Add-ins. At the bottom, select "Excel Add-ins" from the Manage dropdown and click Go. Note the paths listed for any active add-ins. These files contain macros that run within the context of those add-ins.
Common Mistakes
One frequent error is assuming that closing a workbook deletes its macros. It does not; the macros remain embedded in the file unless you explicitly delete them via the VBA editor. Another mistake is looking for the Personal Macro Workbook in the standard Documents folder. It is almost always hidden in the AppData (Windows) or Library (Mac) directories, which are not visible by default. Users also often forget that macros cannot be saved in standard .xlsx files. If you try to save a workbook with macros as .xlsx, Excel will warn you that the macros will be lost. You must save as .xlsm (Macro-Enabled Workbook) to retain them.
Tips
If you plan to use a macro across many different workbooks, always record it into the Personal Macro Workbook. This saves you from having to copy-paste code between files. To make the Personal Macro Workbook easier to edit, you can unhide it. In the VBA editor, right-click the "VBAProject (PERSONAL.XLSB)" item and select Properties. Change the Visible attribute to True. This makes the workbook appear in the Excel window list, allowing you to edit it like a normal spreadsheet. Remember to set it back to False before closing to avoid accidental edits.
Back up your PERSONAL.XLSB file regularly. Since it contains all your global automation tools, losing it due to a corrupt profile or OS reinstall means losing all your custom shortcuts. Copy the file to a secure cloud drive or external backup monthly.
Troubleshooting
If you cannot find the XLSTART folder on Windows, ensure that hidden files and folders are visible. In File Explorer, go to the View tab and check the box for "Hidden items." Also, verify that you are typing the correct environment variable. On some corporate networks, the path might differ, so searching for "PERSONAL.XLSB" using the Windows search bar in your user profile directory is a reliable alternative.
If the Personal Macro Workbook does not load automatically, check if it exists in the XLSTART folder. If it is missing, create a new one by recording a dummy macro and selecting "Personal Macro Workbook" as the destination. Excel will generate the file and place it in the correct location. If you receive a security warning about macros being disabled, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and adjust the security level to allow macros from trusted locations.
Frequently Asked Questions
Can I move a macro from a workbook to the Personal Macro Workbook?
Yes. Open the VBA editor (Alt + F11). Right-click the module containing the macro in your workbook and select "Export File." Save the .bas file to your desktop. Then, right-click the Modules folder in the PERSONAL.XLSB project and select "Import File." Choose the .bas file you just exported. Finally, delete the original module from the workbook if desired.
Why can't I see the Personal Macro Workbook in my Excel window?
The Personal Macro Workbook is designed to be hidden so it doesn't clutter your workspace. It runs in the background. To see it, you must either open the VBA editor and change its visibility property to True, or simply recognize that it is loaded by checking the Project Explorer in the VBA editor.
Do macros stay on my computer if I uninstall Excel?
No. Uninstalling Excel typically removes the application files, but it may leave user data behind depending on your settings. However, the XLSTART folder and its contents are part of the user profile. If you wipe your user profile or reset your PC without backing up the AppData/Library folders, your macros will be lost. Always back up the PERSONAL.XLSB file separately.
Can I share my Personal Macro Workbook with other users?
You can share the PERSONAL.XLSB file, but it is not recommended for direct sharing because it contains personal settings and potentially sensitive code. Instead, export specific modules as .bas files and send them to colleagues. They can import these modules into their own workbooks or their own Personal Macro Workbooks. Alternatively, package frequently used macros into an Excel Add-in (.xlam), which is easier to distribute and install.
Is there a difference in storage location between Excel 2016, 2019, and 365?
The fundamental storage logic remains the same: workbook macros are embedded in the file, and global macros are in the XLSTART folder. However, the exact path to the XLSTART folder can vary slightly between versions and installation types (Click-to-Run vs. MSI). For Office 365, the path is generally consistent with newer versions, but checking the %appdata% shortcut is the most reliable method across all modern versions.