![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Location: UK - London
Posts: 19
|
I need to write a piece of code which will open a workbook and delete one of it's VBA modules.
Any suggections? Thanks |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
You need to set a reference to the VBIDE in Tools-References from the VB editor (the name is "Microsoft Visual Basic X.X Extensibility"). Then you can do something like this:
Code:
Sub DelModule()
Dim VBP As Object
Set VBP = ActiveWorkbook.VBProject
VBP.VBComponents.Remove (VBP.VBComponents("Module2"))
Set VBP = Nothing
End Sub
Russell |
|
|
|
|
|
#3 |
|
New Member
Join Date: Feb 2002
Location: UK - London
Posts: 19
|
Great - thanks.
Do I use a silimar method is I just decide to delete a Sub routine within a module? |
|
|
|
|
|
#4 | |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
Nope use something like what Chip has created:
Quote:
Define the module and procedure name. HTH. Cheers, Nate |
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
What about just a single line of code like in workbookopen event?
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
all i could come up with was
Sub DeleteProcedureWB() DisplayAlerts = False Dim VBCodeMod As Object Dim StartLine As Long Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule With VBCodeMod StartLine = (3) .Deletelines StartLine End With ActiveWorkbook.Save End Sub it works but can u specify text to delete? |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|