drom
Active Member
- Joined
- Mar 20, 2005
- Messages
- 498
- Office Version
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
Hi and Thanks in advance!!
if I use the following macro I can delete all the module etc from a specific Workbook.
'
but is there a way of deleting a specific module whithout the use of For Each VBComp In VBComps
I mean some thing like:
Activeworkbook.VBComponents("Module 1").remove
if "module 1" is the module I want to delete
Thanks!
PS: I know the following web
if I use the following macro I can delete all the module etc from a specific Workbook.
'
Code:
Sub Delete_AllVBA()
On Error Resume Next
Dim WkbName As String: WkbName = "c\:gvjvcjhgsdf\vfdmnbvv\Hello.xls" 'ThisWorkbook.Name
Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents: Set VBComps = Workbooks(WkbName).VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule: VBComps.Remove VBComp '1: "Standard Module"
Case vbext_ct_ClassModule: VBComps.Remove VBComp '2: "Class Module"
Case vbext_ct_MSForm: VBComps.Remove VBComp '3: "MS Form"
Case vbext_ct_ActiveXDesigner: VBComps.Remove VBComp '11: "ActiveX Designer"
Case vbext_ct_Document: 'VBComps.Remove VBComp '100:"Document"
With VBComp.CodeModule
If .CountOfLines > 0 Then
.DeleteLines 1, .CountOfLines
End If
End With
End Select
Next VBComp
Beep
End Sub
'
but is there a way of deleting a specific module whithout the use of For Each VBComp In VBComps
I mean some thing like:
Activeworkbook.VBComponents("Module 1").remove
if "module 1" is the module I want to delete
Thanks!
PS: I know the following web
HTML:
http://www.cpearson.com/excel/vbe.aspx