PC Review


Reply
Thread Tools Rate Thread

delete macro from vbs

 
 
=?Utf-8?B?c3dhbnNvbmc=?=
Guest
Posts: n/a
 
      20th Apr 2007
Hello,

I would like to remove a macro from a workbook after it has run.

Any thoughts?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      20th Apr 2007
Seems a bit drastic but here goes, put this in your macro:-

Sub macrosuicide()
Dim vbCom As Object
MsgBox "There's no going back now I hope you have a backup --DELETING--"
Set vbCom = Application.VBE.ActiveVBProject.VBComponents
vbCom.Remove VBComponent:=vbCom.Item("Module1") '<Change as required
End Sub

Mike

"swansong" wrote:

> Hello,
>
> I would like to remove a macro from a workbook after it has run.
>
> Any thoughts?

 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      20th Apr 2007
Hi Swansong,

Try the code posted by Chip Pearson:

'=============>>
Sub SelfDestruct()
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long

'Your code

Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents("NewModule").CodeModule
With VBCodeMod
StartLine = .ProcStartLine("SelfDestruct", vbext_pk_Proc)
HowManyLines = .ProcCountLines("SelfDestruct", vbext_pk_Proc)
.DeleteLines StartLine, HowManyLines
End With

End Sub
'<<=============


See also Chip Pearson's Pogramming to the VBE page at:

Programming To The Visual Basic Editor
http://www.cpearson.com/excel/vbe.htm

Note Chip' instructions to set a reference to the VBA
Extensibility library.


---
Regards,
Norman


 
Reply With Quote
 
=?Utf-8?B?c3dhbnNvbmc=?=
Guest
Posts: n/a
 
      20th Apr 2007
That works! Just had to change some security settings in excel.

"Mike H" wrote:

> Seems a bit drastic but here goes, put this in your macro:-
>
> Sub macrosuicide()
> Dim vbCom As Object
> MsgBox "There's no going back now I hope you have a backup --DELETING--"
> Set vbCom = Application.VBE.ActiveVBProject.VBComponents
> vbCom.Remove VBComponent:=vbCom.Item("Module1") '<Change as required
> End Sub
>
> Mike
>
> "swansong" wrote:
>
> > Hello,
> >
> > I would like to remove a macro from a workbook after it has run.
> >
> > Any thoughts?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a “Delete Column” Macro to a “Delete Row” Macro cardan Microsoft Excel Programming 7 15th May 2010 06:38 PM
Macro to delete current row AND delete objects also located in thatrow. Tonso Microsoft Excel Discussion 3 27th Jan 2009 02:43 PM
Re: Macro to delete sheets and saves remaining file does not properly delete module gazornenplat Microsoft Excel Programming 0 22nd Jun 2005 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Microsoft Excel Programming 7 21st Jun 2005 05:16 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Microsoft Excel Programming 4 3rd May 2004 08:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:43 PM.