Excel Guides

Deleting Macros from Within a Macro in Excel

Deleting macros from within a macro in Excel is a relatively simple process. To do so, simply follow these steps:

  1. Open the Visual Basic Editor (VBE) by pressing Alt+F11. This will open the VBE window.
  2. Click on the Tools menu and select References. This will open the References dialog box.
  3. In the References dialog box, scroll down until you see the entry for Microsoft Excel XX.X Object Library. XX.X corresponds to the version of Excel you are using (e.g., Microsoft Excel 16.0 for Excel 2016). Select this entry and click OK. This will add a reference to the Excel object library, which we will need in order to access the Excel object model from within our macro.
  4. Now that we have added a reference to the Excel object library, we can start writing our macro. In the VBE window, click on Insert, then Module. This will insert a new module into which we can write our macro.
  5. (Optional): If you want your macro to be available in all workbooks, you can save it in your Personal Macro Workbook (PMW). To do so, simply click on the File menu and select Save Personal Macro Workbook.... This will open the Save As dialog box. In the Save As dialog box, make sure that you save your file with a .xlsm extension (e.g., "My Macros.xlsm") and click Save & Close. Your macro will now be saved in your PMW and will be available in all workbooks.


  6. (Note: If you want your macro to be available only in the current workbook, you can skip this step.)


  7. (Optional): If you want to give your macro a shortcut key, you can do so by clicking on the Macro Options... button in the VBE toolbar. This will open the Macro Options dialog box.

    In the Macro Options dialog box, enter the shortcut key you want to use for your macro in the Shortcut key text box.

    (Note: You can use any combination of Shift, Ctrl, and Alt keys as well as a letter or number key.

    For example, if you wanted to use Ctrl+Shift+M as your shortcut key, you would enter that combination in the Shortcut key text box.

    If you wanted to use just M as your shortcut key, you would enter M in the Shortcut key text box.

    If you wanted to use Shift+M as your shortcut key, you would enter +M in the Shortcut key text box.)

    Once you have entered your shortcut key combination, click "OK" to close the Macro Options dialog box.


  8. (Note: If you do not want to use a shortcut key for your macro, you can skip this step.)


  9. In the module [that we inserted in Step 4] , paste or type < span style =" font_size : 14px " >< span style =" font_family : ' Times New Roman ', serif " >< u > [the following code] :

Move beyond 

Excel

Get started with Causal today.
Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.