Workbook_Open ne fonctionne pas correctement avec Excel
jybse
Messages postés9Date d'inscriptionjeudi 31 mars 2005StatutMembreDernière intervention 4 janvier 2009
-
15 avril 2005 à 06:26
jybse
Messages postés9Date d'inscriptionjeudi 31 mars 2005StatutMembreDernière intervention 4 janvier 2009
-
15 avril 2005 à 13:42
Bonjour à tous,
J'ai une macro Workbook_Open() qui marche lorsque j'ouvre mon classeur pour la première fois dans une session Excel, mais si je ferme mon classeur en ayant fait une BeforeSave, que je reste dans Excel et que je rouvre mon classeur, la macro Workbook_Open() ne fonctionne plus (je dois refermer Excel et le rouvrir). Voici le code :
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = True Then
FileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Xls Files (*.xls), *.xls")
If FileSaveName <> False Then
Application.ScreenUpdating = False
ThisWorkbook.Unprotect "password"
Sheets("Titre").Visible = False
Sheets("Avis").Visible = True
Sheets("Resultat").Visible = False
ThisWorkbook.Protect "password"
Application.EnableEvents = False
ThisWorkbook.SaveAs FileSaveName
Application.EnableEvents = True
ThisWorkbook.Unprotect "password"
Sheets("Titre").Visible = True
Sheets("Avis").Visible = False
Sheets("Resultat").Visible = True
ThisWorkbook.Protect "password"
' puis, pour ne pas être invité inutilement à enregistrer si on quitte
ThisWorkbook.Saved = True
End If
Cancel = True
Exit Sub
End If
Application.ScreenUpdating = False
ThisWorkbook.Unprotect "password"
Sheets("Titre").Visible = False
Sheets("Avis").Visible = True
Sheets("Resultat").Visible = False
ThisWorkbook.Protect "password"
Application.EnableEvents = False
ThisWorkbook.Save
Application.EnableEvents = True
ThisWorkbook.Unprotect "password"
Sheets("Titre").Visible = True
Sheets("Avis").Visible = False
Sheets("Resultat").Visible = True
ThisWorkbook.Protect "password"
' puis, pour ne pas être invité inutilement à enregistrer si on quitte
ThisWorkbook.Saved = True
Cancel = True
Exit Sub
End Sub
Private Sub Workbook_Open()
Application.ScreenUpdating = False
ThisWorkbook.Unprotect "password"
Sheets("Titre").Visible = True
Sheets("Avis").Visible = False
Sheets("Resultat").Visible = True
CreateCustomMenuWithSubMenus
ThisWorkbook.Protect "password"
Application.ScreenUpdating = True
' puis, pour ne pas être invité inutilement à enregistrer si on quitte
ThisWorkbook.Saved = True
End Sub
jybse
Messages postés9Date d'inscriptionjeudi 31 mars 2005StatutMembreDernière intervention 4 janvier 2009 15 avril 2005 à 13:42
Merci pour votre aide, mais ça ne marche pas. De toute façon, je ne souhaite pas quitter après avoir sauvegardé. J'ai essayé votre code : après avoir sauvegardé, Excel m'a demandé si je voulais quitter, j'ai dit oui pour voir, quand j'ai rouvert le classeur, Workbook_Open n'avait pas fonctionné.