Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default delete macro from vbs

Hello,

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

Any thoughts?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default delete macro from vbs

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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default delete macro from vbs

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").C odeModule
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default delete macro from vbs

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:16 PM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:11 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:54 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 04:38 PM


All times are GMT +1. The time now is 06:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"