Solved

Excel --- Deleting a Macro?

Posted on 2000-03-13
3
167 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
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now