Salut,
un option private module en haut de tes modules permettent de ne pas pouvoir lancer les macros par Alt+f8 ou apr outils/macro
Pour masquer le code aux utilisateurs tu peux verouiller l'affichage de ton projet dans VBE outils/propriétés de VBA project/protection.
Pour supprimer le code tu lances macrokiller dans l'évènement beforeclose de thisworkbook(si tu n'as pas protéger ton projet) macrokiller thisworkbook
Sub MacroKiller(C As Workbook) 'Coche Faire confiance au projet Visual Basic
Dim VBC As Object
On Error GoTo Errr
With C.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With
Errr: 'le sendkeys est valable pour les versions Fr
If Err = 1004 Then SendKeys "%om2d%r~", True: MacroKiller C
End Sub
'-----------------------si tu as protéger ton projet----------------------------
'dans le module thisworkbook
'mets en commentaire la procédure quitter pour faire tes tests
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
UnprotectVBProject ThisWorkbook, "Lemotdepasse"
MacroKiller ThisWorkbook
Quitter
End Sub
'dans un module standard copies ceci
Sub UnprotectVBProject(WB As Workbook, ByVal Password$) 'trouvé chez FRed Sig
Dim vbProj As Object
Set vbProj = WB.VBProject
If vbProj.Protection <> 1 Then Exit Sub
Set Application.VBE.ActiveVBProject = vbProj
SendKeys Password & "~~"
Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
DoEvents 'rajout perso
End Sub
Sub MacroKiller(C As Workbook) 'Coche Faire confiance au projet Visual Basic
Dim VBC As Object
On Error GoTo Errr
With C.VBProject
For Each VBC In .VBComponents
If VBC.Type = 100 Then
With VBC.CodeModule
.DeleteLines 1, .CountOfLines
.CodePane.Window.Close
End With
Else: .VBComponents.Remove VBC
End If
Next VBC
End With
Errr: 'le sendkeys est valable pour les versions Fr
If Err = 1004 Then SendKeys "%om2d%r~", True: MacroKiller C
End Sub
Sub Quitter()
Application.Quit
SendKeys "%o"
End Sub
Toutefois, un utilisateur un peu averti fera sauter facilement la protection sous Excel.
A+++