Hi
I'm trying to run this Sub before closing my workbook. If this is the only workbook open, I want to quit excel, but if there's more workbooks open, I just want to close this one. My problem is that the messagebox appear two times. Does enyone know how to fix this? I tried to put in the enableevents property, but I don't even know if I'm on the right track here...
![]()
Sub Auto_Close() Dim answer As Integer answer = MsgBox("Alle endringer du har gjort vil bli lagret. Der som du ikke ønsker dette, må de omgjøres før du avslutter. Vil du fortsatt avslutte?", vbYesNo + vbQuestion, "VIKTIG") If answer = vbYes Then Application.ScreenUpdating = False Worksheets("Brukerlogg").Activate ActiveSheet.Unprotect Password:="password" Range("F10").Value = Now() ActiveSheet.Protect Password:="password" Application.DisplayFullScreen = False Application.ScreenUpdating = True ThisWorkbook.Save Application.EnableEvents = False If Worksheets.Count < 1 Then ThisWorkbook.Close Else Application.Quit End If Application.EnableEvents = True Else Cancel = True End If End Sub
Bookmarks