Solved: Prompt to save on close (askes if already saved?)
I pulled this code from another post.
I modified it to direct the user to enable macros on open,
and it hides sheets on close to stop the user from working if the macros are not enabled.
On close, even if I've saved my work, it asks to save the file.
I see that it does this because of the contents in [A1000] change if saved,
and that new change prompts the new save.
Will screenupdating and display alerts set to false allow the save without prompts and perform the file changes on close?
here is the code so far...
- thank you in advance -
[VBA]Private Sub Workbook_Open()
Dim Sheet As Worksheet
'make all sheets visible
For Each Sheet In Worksheets
If Sheet.Name <> "Prompt" Then
Sheet.Visible = xlSheetVisible
End If
Next Sheet
'hide the prompt and go to A1 on sheet1
Sheets("Prompt").Visible = xlSheetVeryHidden
'Application.GoTo Sheets("QCDetail").[A1], Scroll:=True
'clean up
Set Sheet = Nothing
ActiveWorkbook.Saved = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Sheets("Prompt")
'if book is already saved, make a note of it
If ActiveWorkbook.Saved = True Then .[A1000] = "Saved"
'make prompt sheet visible
Dim Sheet As Worksheet
.Visible = xlSheetVisible
'hide all other sheets
For Each Sheet In Worksheets
If Sheet.Name <> "Prompt" Then
Sheet.Visible = xlSheetVeryHidden
End If
Next Sheet
'if the book is already saved, delete
'the previous note and close the book
If .[A100] = "Saved" Then
.[A1000].ClearContents
ActiveWorkbook.Save
End If
'clean up
Set Sheet = Nothing
End With
End Sub
[/VBA]
Not sure how to avoid prompt
I'm still learning VBA and I'm not confident about everything that happens in the code. I don't know if the "saved" line helps a step in the process.
I pulled out what I don't think I need, but I'm not sure how to avoid the save prompt if they have already saved.
I am hidding sheets, and that change prompts for a save.
I hid screen updating and display alerts but not sure what I'm missing...
[VBA]
Private Sub Workbook_Open()
Dim Sheet As Worksheet
'make all sheets visible
For Each Sheet In Worksheets
If Sheet.Name <> "Prompt" Then
Sheet.Visible = xlSheetVisible
End If
Next Sheet
'hide the prompt sheet
Sheets("Prompt").Visible = xlSheetVeryHidden
'clean up
Set Sheet = Nothing
' ActiveWorkbook.Saved = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Sheets("Prompt")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'make prompt sheet visible
Dim Sheet As Worksheet
.Visible = xlSheetVisible
'hide all other sheets
For Each Sheet In Worksheets
If Sheet.Name <> "Prompt" Then
Sheet.Visible = xlSheetVeryHidden
End If
Next Sheet
Set Sheet = Nothing
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
[/VBA]