Create and save all your macros in a single workbook
When you first create a macro in a workbook, it works only in that workbook. But what if you want to use the macro in other workbooks? To make your macros available every time you open Excel, you can create them in a workbook called Personal.xlsb. That's a hidden workbook stored on your computer, which opens in the background every time you open Excel.
Macros and VBA tools can be found on the Developer tab, which is hidden by default, so the first step is to enable it. For more information, see Show the Developer tab.
Next, create a macro. We'll record a macro that does nothing, but will create the Personal Macro workbook.
You can learn more about creating macros in Quick start: Create a macro.
-
Go to the Developer tab, and click Record Macro.
-
In the Record Macro dialog box, don't bother entering a name for the macro in the Macro name box. You can accept the name that Excel gives you, such as Macro1, since this is just a temporary macro.
When you do start creating macros of your own, you'll want to give them descriptive names, so you know what they do.
-
In the Store macro in box, pick Personal Macro Workbook > OK. This is the most important step, because if you don't already have a Personal Macro Workbook, Excel will create one for you.
-
Click Developer > Stop Recording, and Excel will have created your Personal Macro worbook.
-
When you close the workbook, you'll be prompted to save both the workbook, and the Personal Macro workbook.
To see the macro you created:
-
Go to Developer > Visual Basic to launch the Visual Basic Editor (VBE), which is where your macros are stored.
-
You can find your Personal Macro workbook in the Project Explorer pane on the left hand side. If you don't see it, go to View > Project Explorer.
-
Double-click on the VBA Project (PERSONAL.xlsb) folder > Modules > Module1, and you'll find the empty Macro1 that you recorded. You can delete it, or keep it to add code to later.
Note: When you record a macro in a new instance of Excel, VBA will automatically create a new Module folder and increment its number. So if you already have Module1 and Module2, VBA will create Module3. You can rename Modules in the Properties window beneath the Project Explorer, so they better reflect what the macros inside them do.
Moving macros from one computer to another
Your Personal.xlsb file is stored in a folder called XLSTART. If you want to share your macros with someone else, you can copy it to the XLSTART folder on other computers, or copy some or all of its macros to the Personal.xlsb file on other computers. You can search for XLSTART in Windows Explorer to locate it.
If you have one or just a few macros that you want to share with others, you can send them the workbook that contains them. You can also make the workbook available on a shared network drive or from a SharePoint Services library.
For more information about copying a macro from one workbook to another, see Copy a macro module to another workbook.
Make sure the Developer tab is visible on the ribbon. By default, the Developer tab is not visible, so do the following:
-
Go to Excel > Preferences… > Ribbon & Toolbar.
-
In the Customize the Ribbon category, in the Main Tabs list, select the Developer check box, and then click Save.
Next, create a macro. We'll record a macro that does nothing, but will create the Personal Macro workbook.
You can learn more about creating macros in Quick start: Create a macro.
-
Go to the Developer tab, and click Record Macro.
-
In the Record Macro dialog box, don't bother entering a name for the macro in the Macro name box. You can accept the name that Excel gives you, such as Macro1, since this is just a temporary macro.
When you do start creating macros of your own, you'll want to give them descriptive names, so you know what they do.
-
In the Store macro in box, pick Personal Macro Workbook > OK. This is the most important step, because if you don't already have a Personal Macro Workbook, Excel will create one for you.
-
Click Developer > Stop Recording, and Excel will have created your Personal Macro worbook.
-
When you close the workbook, you'll be prompted to save both the workbook, and the Personal Macro workbook.
To see the macro you created:
-
Click Developer > Visual Basic to launch the Visual Basic Editor (VBE), which is where your macros are stored.
-
You can find your Personal Macro workbook in the Project Explorer pane on the left hand side. If you don't see it, go to View > Project Explorer.
-
Double-click on the VBA Project (PERSONAL.xlsb) folder > Modules > Module1, and you'll find the empty Macro1 that you recorded. You can delete it, or keep it to add code to later.
Note: When you record a macro in a new instance of Excel, VBA will automatically create a new Module folder and increment its number. So if you already have Module1 and Module2, VBA will create Module3. You can rename Modules in the Properties window beneath the Project Explorer, so they better reflect what the macros inside them do.
Moving macros from one computer to another
Your Personal.xlsb file is stored in a system startup folder. If you want to share your macros with someone else, you can copy Personal.xlsb to the startup folder on other computers, or copy some or all of its macros to the Personal.xlsb file on other computers. In Finder select Go, then hold down the Option key, and select Library. In the Library pane, navigate to: Group Containers > xyz.Office (where xyz be a text string, like "UBF8T346G9") > User Content > Startup > Excel. Paste your Personal.xlsb file into the Excel folder.
If you have one or just a few macros that you want to share with others, you can send them the workbook that contains them. You can also make the workbook available on a shared network drive or from a SharePoint Services library.
For more information about copying a macro from one workbook to another, see Copy a macro module to another workbook.
Need more help?
You can always ask an expert in the Excel Tech Community, get support in the Answers community, or suggest a new feature or improvement on Excel User Voice.
No comments:
Post a Comment