I have been playing around with scripts trying to delete modules from ALL workbooks but no matter what I try it only deletes them from the current active workbook, can someone please help.
I have read other forum threads on this site and Chip Pearsons but nothing seemes to work.
Before anyone asks, YES the module names are correct.
The first code I tried was.
the next one I tried is
I have also tried
I have read other forum threads on this site and Chip Pearsons but nothing seemes to work.
Before anyone asks, YES the module names are correct.
The first code I tried was.
Code:
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule
modName = VBComp.Name
'If modName = "X_Ranges_And_Settings" Then
'VBComps.Remove VBComp
' End If
If modName = "X_Ranges_And_Settings1" Then
VBComps.Remove VBComp
End If
If modName = "X_Ranges_And_Settings2" Then
VBComps.Remove VBComp
End If
End Select
Next VBComp
the next one I tried is
Code:
For Each Wb In Workbooks
If Wb.Name <> "List1" Then
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule
modName = VBComp.Name
'If modName = "X_Ranges_And_Settings" Then
'VBComps.Remove VBComp
' End If
If modName = "X_Ranges_And_Settings1" Then
VBComps.Remove VBComp
End If
If modName = "X_Ranges_And_Settings2" Then
VBComps.Remove VBComp
End If
End Select
Next VBComp
End If
Next Wb
I have also tried
Code:
Sub DeleteModule()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("X_Ranges_And_Settings1")
VBProj.VBComponents.Remove VBComp
End Sub