View Single Post
 
Old 07-12-2023, 04:49 AM
ksor ksor is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 78
ksor is on a distinguished road
Default Problems with ThisWorkbook.Saved not working ?

I have a workbook with few sheets in it.

I the beforeClose I use ThisWorkbook.Saved to show a enhanged dialog explaining in danish the situation for the user - it's just the normal problematic ... do you want to save or not or cancel then close the file - here is the code:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'   Application.DisplayFormulaBar = True
'   ActiveWindow.Zoom = initZoom
'   ActiveSheet.Range("A1").Select
    '
    Dim svar As Byte
    If ThisWorkbook.Saved = False Then
        svar = MsgBox("Du har lavet ændringer på et af arkene - bevidst eller ubevidst !" & vbLf & vbLf & _
                 "Er du USIKKER på, hvad du har lavet --> så svar NEJ til at gemme !" & vbLf & vbLf & _
                 "Overvej nøje HVAD du har lavet, og besvar så dette: 'Vil du gemme ?'", _
                 vbYesNoCancel + vbDefaultButton2, "ADVARSEL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
        If svar = vbYes Then
            ThisWorkbook.Save
        ElseIf svar = vbNo Then
            ThisWorkbook.Saved = True
        ElseIf svar = vbCancel Then
            Cancel = True
        End If
    End If
End Sub
If I just open the file and close it again the dialog shows up ... as though the ThisWorkbook.Saved is False ... but I'm not aware of making any changes or having some vba that do any changes to the file !

How can I find out where the chance happens ?
Reply With Quote