ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can a macro delete itself (and others)? (https://www.excelbanter.com/excel-programming/335792-can-macro-delete-itself-others.html)

mdb

Can a macro delete itself (and others)?
 
From an Excel VBA app (running as an excel macro) is it possible to delete
the macro and all other macros, while the present macro is running? If so,
how?


--
-mdb

Norman Jones

Can a macro delete itself (and others)?
 
Hi MDB,

See ChipPearson at:

http://www.cpearson.com/excel/vbe.htm

And, previously posted by Chip:

Sub SelfDestruct()

Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long

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


---
Regards,
Norman



"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com wrote in message
. ..
From an Excel VBA app (running as an excel macro) is it possible to delete
the macro and all other macros, while the present macro is running? If
so,
how?


--
-mdb




Ron de Bruin

Can a macro delete itself (and others)?
 
See
http://www.cpearson.com/excel/vbe.htm

Here is example

With One macro named "TheMacro" in Module1
The simplest way is to delete the entire module with contains the procedure.

Sub TheMacro()
'
' your code
'
With ThisWorkbook.VBProject.VBCompo*nents
.Remove .Item("Module1")
End With
End Sub

But this must be checked to do this
http://www.j-walk.com/ss/excel/tips/tip96.htm



--
Regards Ron de Bruin
http://www.rondebruin.nl


"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com wrote in message . ..
From an Excel VBA app (running as an excel macro) is it possible to delete
the macro and all other macros, while the present macro is running? If so,
how?


--
-mdb




Ron de Bruin

Can a macro delete itself (and others)?
 
That stupid Google Beta<g

Note the - in the code in y other reply

Sub TheMacro()
'
' your code
'
With ThisWorkbook.VBProject.VBComponents
.Remove .Item("Module1")
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
See
http://www.cpearson.com/excel/vbe.htm

Here is example

With One macro named "TheMacro" in Module1
The simplest way is to delete the entire module with contains the procedure.

Sub TheMacro()
'
' your code
'
With ThisWorkbook.VBProject.VBCompo*nents
.Remove .Item("Module1")
End With
End Sub

But this must be checked to do this
http://www.j-walk.com/ss/excel/tips/tip96.htm



--
Regards Ron de Bruin
http://www.rondebruin.nl


"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com wrote in message . ..
From an Excel VBA app (running as an excel macro) is it possible to delete
the macro and all other macros, while the present macro is running? If so,
how?


--
-mdb







All times are GMT +1. The time now is 01:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com