Remove macro programmatically

M

macroapa

Hi I have the following proceedure sat in a worksheet (sheet1):

Private Sub CommandButton1_Click()
RefreshSheets
End Sub

I have been able to successfully get rid of the sub called
'RefreshSheets' from my module, so the code does absolutely nothing
(and CommandButton1 has also been deleted programatically), but how to
I get rid of this redundant code that remains.

I need to remove it as the workbook still thinks it contains a macro
(even tho there is no actual code within the resulting sub!) and so
when I email the workbook, the recipients email client rejects it as
harmful.

Any help greatly appreciated.

Cheers!
 
D

Dave Peterson

Rightclick on that worksheet tab that used to own that button.
Select View Code
Select the code window
hit ctrl-a to select all the text in that window
hit the delete key to clear that window

Save the workbook.


Debra Dalgleish shows how to clean up all the remnants of macros:
http://www.contextures.com/xlfaqMac.html#NoMacros
 
J

Jim Thomlinson

From Chip Pearson's web site...
http://www.cpearson.com/excel/vbe.aspx
Deleting All VBA Code In A Project

This code will delete ALL VBA code in a VBProject.

Sub DeleteAllVBACode()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule

Set VBProj = ActiveWorkbook.VBProject

For Each VBComp In VBProj.VBComponents
If VBComp.Type = vbext_ct_Document Then
Set CodeMod = VBComp.CodeModule
With CodeMod
.DeleteLines 1, .CountOfLines
End With
Else
VBProj.VBComponents.Remove VBComp
End If
Next VBComp
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top