Solved

Excel --- Deleting a Macro?

Posted on 2000-03-13
3
173 Views
Last Modified: 2012-05-04
Hi,

How can I delete all macros on a workbook/worksheet using VBA?

Thanks.
0
Comment
Question by:SLE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
MTroutwine earned 50 total points
ID: 2612217
I don't know of a way to delete the macros' themselves but you can delete the module that they reside in:

Sub DeleteModule()
   
    ' Local Variable Declarations:
    Dim objModule As Object
    Dim wbkBook As Workbook
   
    ' **** THIS LINE IS OPTIONAL IF THE SPREADSHEET IS
    ' **** ALREADY OPEN YOU DON'T NEED IT!
    'Workbooks.Open FileName:="C:\Book1.xls"
       
    ' Instantiate the objects:
    Set wbkBook = ActiveWorkbook
    Set objModule = wbkBook.Excel4IntlMacroSheets
   
    ' Delete the module:
    objModule.Remove VBComponent:=objModule.Item("Module2")

End Sub

Hope this helps!
:>)
0
 
LVL 22

Expert Comment

by:ture
ID: 2612422
SLE,

This procedure deletes all VBA code in the active workbook.

Sub DeleteAllVBACode()
  'For this to work, you must set a reference to the
  'MS Visual Basic for Applications Extensibility library
 
  Dim vbc As VBComponent
  Dim cm As CodeModule
  For Each vbc In ActiveWorkbook.VBProject.VBComponents
    Set cm = vbc.CodeModule
    cm.DeleteLines 1, cm.CountOfLines
  Next vbc
End Sub

Ture Magnusson
Karlstad, Sweden
0
 
LVL 2

Author Comment

by:SLE
ID: 2614903
Thanks also to ture...
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question