How to remove VBA Project From Excel

There will be times when you want to remove a particular macro from a document (or template) and there are a few ways you can do this:
1) Using the Macro dialog box
2) Using the Visual Basic Editor


Using the Macro dialog box

You can delete a macro using the Macro dialog box. Select (Tools > Macro > Macros).
Select the name of the macro you want to delete from the list and press the "Delete" button.

How to remove VBA Project From Excel

This will remove the macro from its corresponding code module.
Using this method will not remove any empty code modules from your VBA Project.


Using the Visual Basic Editor

You can also delete macros manually by displaying the Visual Basic Editor.
This window can be displayed by selecting (Tools > Macro > Visual Basic Editor) or by pressing (Alt + F11).
You will need to locate the Project in the Project Explorer window. This should appear in the top left corner. If you cannot see it, select (View > Project Explorer).
There should be a project there called VBAProject followed by the name of the document in brackets. Expand this project.
Select the Modules node and expand it. This will list all the code modules that are contained within this document.
You can double click on any module to display the corresponding code window.
Once you have located the macro in question, you can highlight it with the mouse and press the Delete key.

How to remove VBA Project From Excel


Deleting all the Macros

If you want to delete all the macros from a document then it is much easier to do this using the Visual Basic Editor.
This way you can use the shortcut menu to quickly remove a code module from the project.
Select the code module you want to delete and press the right mouse button and select "Remove Module".
You will be asked if you want to export the module first. Select "No".

How to remove VBA Project From Excel



© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions LimitedTopPrevNext

How to remove VBA Project From Excel


 

Excel

Remove All VBA Code Programmatically

How to remove VBA Project From Excel

Ease of Use

Intermediate

Version tested with

2002 

Submitted by:

Jacob Hilderbrand

Description:

A method to use VBA code to remove all VBA code in a workbook. 

Discussion:

You have a lot of modules, userforms, and other code in a workbook and you want to delete it all at once. You could manually delete each one, one at a time, or you can use VBA to do all the work for you. 

Code:

instructions for use

			

Option Explicit Sub DeleteAllCode() Dim x As Integer Dim Proceed As VbMsgBoxResult Dim Prompt As String Dim Title As String Prompt = "Are you certain that you want to delete all the VBA Code from " & _ ActiveWorkbook.Name & "?" Title = "Verify Procedure" Proceed = MsgBox(Prompt, vbYesNo + vbQuestion, Title) If Proceed = vbNo Then MsgBox "Procedure Canceled", vbInformation, "Procedure Aborted" Exit Sub End If On Error Resume Next With ActiveWorkbook.VBProject For x = .VBComponents.Count To 1 Step -1 .VBComponents.Remove .VBComponents(x) Next x For x = .VBComponents.Count To 1 Step -1 .VBComponents(x).CodeModule.DeleteLines _ 1, .VBComponents(x).CodeModule.CountOfLines Next x End With On Error GoTo 0 End Sub

How to use:

  1. Open Excel.
  2. Press Alt + F11 to open VBE.
  3. Paste the code there.
  4. Close VBE (Alt + Q or press the X in the top right hand corner).
  5. Open the workbook that you want to remove all the code from.
  6. The VBA Project for that workbook must be unlocked (if it is protected).
  7. Trust Access To Visual Basics Project must be enabled.
  8. From Excel: Tools | Macro | Security | Trusted Sources.
  9. Tools | Macro | Macros (Select "DeleteAllCode" and press Run).
 

Test the code:

  1. Refer to the "How To Use" Section.
  2. Download the attachment for a working example.
 

Sample File:

DeleteAllCode.zip 7.81KB 

Approved by mdmackillop

This entry has been viewed 368 times.

How do I delete a VBA macro in Excel?

Delete a macro.
On the Developer tab, click Macros..
In the list, click the macro that you want to delete, and click the delete button..

How do I remove a VBA project from Word?

In Word or Excel, click View > Macro > View Macros. In PowerPoint, click View > Macro. In the Macro box, pick the macro you want to remove and click Delete.

How to turn off Microsoft Visual Basic for Applications in Excel?

To do this, follow these steps: In Office Setup, on the Choose installation options for all Office applications and tools page, in the Features to install list, expand Office Shared Features. Click Visual Basic for Applications, and then click Not Available.

How do I unprotect a VBA project?

Technique to Unprotect VBA Project in Excel Without Password.
Open new Microsoft Word file..
Now, press Alt + F11 keys..
Click on Insert and select a Module..
Then, Enter the following code in the General Window > > Press F5..
Now, select the Word file to unlock >> click Open..