i

Comment empêcher des utilisateurs d'enregistrer un classeur en le fermant ?


Voici 2 macros à mettre dans un module standard


Sub empecheEnr()

With Application.CommandBars("Standard")

.Controls("Enre&gistrer").Enabled = False

End With

With Application.CommandBars("Worksheet Menu Bar")

.Controls("Fichier").Enabled = False

End With

'desactive le raccourci clavier Ctrl+S,

'Application.OnKey "s^", ""

End Sub


Sub depecheEnr()

With Application.CommandBars("Standard")

.Controls("Enre&gistrer").Enabled = True

End With

With Application.CommandBars("Worksheet Menu Bar")

.Controls("Fichier").Enabled = True

End With

''rétabli le raccourci clavier Ctrl+S

'Application.OnKey "", "s^"

End Sub


et ces 3 macros à placer dans le thisworkbook


Option Explicit


Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.DisplayAlerts = False

depecheEnr

ThisWorkbook.Saved = True

ThisWorkbook.Close SaveChanges:=False

End Sub


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

ThisWorkbook.Saved = True

End SubPrivate Sub Workbook_Open()

empecheEnr

End Sub


Voilà. Même l'icône "disquette" est grisée...