Make Excel VBA Module Available to All Workbooks
In this article
To make a VBA module available to all Excel workbooks, you must store it in your Personal Macro Workbook (PERSONAL.XLSB). This hidden workbook opens automatically with Excel and stores macros you want to use across any file. No special setup is required beyond having Excel installed and enabling the Developer tab.
What You'll Need
- Microsoft Excel (any recent version: 2010, 2013, 2016, 2019, 2021, or Microsoft 365)
- Developer tab enabled in Excel (required for accessing the VBA editor and Personal Macro Workbook)
- Basic understanding of VBA modules and macros
Step-by-Step
- Open Excel. Do not open any workbook—start with a blank workbook or the default startup screen.
- Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
- In the VBA editor, look in the Project Explorer window (press Ctrl + R if it’s not visible). If the Project Explorer is hidden, click View > Project Explorer from the top menu.
- Locate VBAProject (PERSONAL.XLSB) in the list. If you don’t see it, your Personal Macro Workbook hasn’t been created yet. To create it, record a dummy macro: go back to Excel, click the Developer tab > Code group > Record Macro. In the dialog box, under Store macro in, select Personal Macro Workbook, give it a name (e.g., “TempMacro”), then click OK and immediately click Stop Recording. This action creates and saves PERSONAL.XLSB in your XLStart folder.
- Back in the VBA editor, under VBAProject (PERSONAL.XLSB), right-click Modules and choose Insert > Module. A new module (e.g., Module1) appears under Modules.
- Copy your VBA code into the new module window. For example:
Public Sub HelloAll() MsgBox "This macro runs from PERSONAL.XLSB and works in any workbook!" End Sub - Save your work by clicking File > Save PERSONAL.XLSB (or Save All if prompted). If PERSONAL.XLSB is not listed under Save, click File > Save As, then select Excel Binary Workbook (*.xlsb) as the file type and ensure the location is your XLStart folder (typically
%APPDATA%\Microsoft\Excel\XLStart). - Close the VBA editor and return to Excel. Open any workbook—your new macro should now appear in the macro list: Developer tab > Code group > Macros (or press Alt + F8).
Common Mistakes
- Creating the module in the wrong workbook: If you paste code into a module inside “VBAProject (Book1.xlsx)” instead of PERSONAL.XLSB, the macro will only be available in that specific file. Always double-check the project name in the Project Explorer.
- Forgetting to save PERSONAL.XLSB: If you close Excel without saving PERSONAL.XLSB, your new module and macros will be lost. Excel may prompt to save changes—say Yes.
- Not enabling the Developer tab: Without it, you can’t easily access the VBA editor, record macros, or manage PERSONAL.XLSB. To enable it: File > Options > Customize Ribbon > check Developer under Main Tabs.
- Using private procedures instead of public ones: If your subroutine is declared as
Private Sub MyMacro(), it won’t appear in the macro list. UsePublic Sub MyMacro()or omit thePublickeyword (since modules default to public). - PERSONAL.XLSB is missing or corrupted: If the file is missing, macros won’t persist. Check the XLStart folder: press Win + R, type
shell:startup, then navigate up one level toMicrosoft\Excel\XLStart. If PERSONAL.XLSB isn’t there, recreate it using the dummy macro method.
Tips
- Use descriptive module names: right-click the module in the Project Explorer and choose Properties to rename it (e.g., change “Module1” to “CommonUtilities”).
- Organize related macros into separate modules (e.g., one for file operations, one for formatting) to keep PERSONAL.XLSB manageable.
- Back up PERSONAL.XLSB regularly. Copy it from the XLStart folder to a safe location—this file contains all your shared macros.
- Test macros in a new workbook before relying on them. Open a blank Excel file, run your macro, and confirm it behaves as expected.
- Use
Application.Volatileonly if needed; overuse can slow down recalculation in large workbooks.
Troubleshooting
If your macro doesn’t appear in the macro list or throws an error, follow these steps:
- Restart Excel: Sometimes changes to PERSONAL.XLSB only take effect after closing and reopening Excel.
- Check macro security settings: Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Ensure Enable all macros (not recommended for production) or Disable all macros with notification is selected. If macros are disabled, Excel won’t load PERSONAL.XLSB or its macros.
- Verify PERSONAL.XLSB is loaded: In Excel, go to View > Unhide. If PERSONAL.XLSB appears in the list, it’s open (though hidden by default). If not, recreate it using the dummy macro method.
- Check for syntax errors: In the VBA editor, click Debug > Compile VBAProject. If errors appear, fix them before saving. A single typo can prevent the entire project from loading.
- Recreate PERSONAL.XLSB: If the file is corrupted, delete PERSONAL.XLSB from the XLStart folder (after backing it up), then create a fresh one by recording a dummy macro as described in Step 4.
- Check for add-ins interfering: Disable all Excel add-ins via File > Options > Add-ins, then restart Excel. If macros appear, re-enable them one by one to find the culprit.
Frequently Asked Questions
Can I store functions (UDFs) in PERSONAL.XLSB?
Yes—user-defined functions (UDFs) work in PERSONAL.XLSB just like macros. Declare them as Public Function MyFunc() and use them like any Excel formula in any workbook.
Will macros in PERSONAL.XLSB work on other computers?
No—PERSONAL.XLSB is tied to your user profile and local Excel installation. To share macros across devices, copy PERSONAL.XLSB to the XLStart folder on each computer, or distribute macros via an Excel add-in (.xlam).
How do I remove or reset macros in PERSONAL.XLSB?
Open PERSONAL.XLSB in the VBA editor (via Alt + F11 > expand PERSONAL.XLSB), delete unwanted modules or procedures, then save. To start fresh, delete PERSONAL.XLSB from the XLStart folder (after backing it up).
Can I password-protect macros in PERSONAL.XLSB?
Yes. In the VBA editor, go to Tools > VBAProject Properties > Protection tab, check Lock project for viewing, and enter a password. This prevents others from viewing or editing your code, but macros will still run if enabled.
Do macros in PERSONAL.XLSB run automatically when Excel starts?
No—they only run when you explicitly execute them (e.g., via the Macros dialog or a shortcut). To run code on startup, create an Auto_Open() subroutine in a standard module, but use this sparingly to avoid performance issues.
Is PERSONAL.XLSB safe from corruption?
It’s relatively safe but not immune. Avoid editing PERSONAL.XLSB while Excel is running other macros, and always save changes before closing. If Excel crashes while PERSONAL.XLSB is open, you may need to restore it from a backup.