Sub StartDeleteModule()
Dim MonClasseur As Workbook
Application.ScreenUpdating = False
On Error Resume Next
Set MonClasseur = Workbooks.Open(Filename:=DialogBox())
If Not err = 0 Then Exit Sub
Call DeleteModule(MonClasseur, "Module1")
Application.ScreenUpdating = True
End Sub
Sub DeleteModule(ByRef Classeur As Workbook, Optional ByVal ModuleName As String)
Dim LeModule As Object, reponse As VbMsgBoxResult
On Error Resume Next
If Len(Classeur.VBProject.VBComponents(ModuleName).Name) <> 0 Then
If err = 0 Then
reponse = MsgBox(" Etes sur de vouloir supprimer le module '" & ModuleName & "' du Classeur '" & Classeur.Name & "' ? ", vbQuestion + vbYesNo)
If reponse = vbYes Then
Set LeModule = Classeur.VBProject.VBComponents(ModuleName)
Classeur.VBProject.VBComponents.Remove LeModule
Else
Exit Sub
End If
Else
MsgBox "Le module spécifié n'à pu être supprimé ! " & vbCrLf & _
"Le module n'existe pas ou vous n'etes pas autorisé à le supprimer.", vbExclamation
End If
End If
End Sub
Function DialogBox(Optional Root As String, Optional DialogTitle As String = "Selection du Classeur...", Optional DialogType As MsoFileDialogType = msoFileDialogFilePicker) As String
With Application.FileDialog(DialogType)
.AllowMultiSelect = False
.Title = DialogTitle
.InitialFileName = Root
If .Show = -1 Then DialogBox = .SelectedItems(1)
End With
End Function