dfenton21
03-19-2009, 02:53 PM
I have my file set up so that it displays one sheet if its opened with macros disabled. I am trying to add another commend into the BeforeClose sub that saves the workbook if the file is not read only. If it is read only, it should just close without a prompt for "Do you want to save..." or "A file named xxx already exists...".
I think the problem is that when the workbook is closed a change is made (hiding/unhiding) so excel prompts with a Save box.
I am a novice to VBA, but I have tried to get it to work. Can someone help please. This is the code I have currently:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Warning").Visible = True
Sheets("Report").Visible = xlVeryHidden
If ActiveWorkbook.ReadOnly Then
Application.DisplayAlerts = False
Else
ActiveWorkbook.Save
End If
End Sub
Instead of Application.DisplayAlerts = False, I have also used ThisWorkbook.Saved=True
Thanks
I think the problem is that when the workbook is closed a change is made (hiding/unhiding) so excel prompts with a Save box.
I am a novice to VBA, but I have tried to get it to work. Can someone help please. This is the code I have currently:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Warning").Visible = True
Sheets("Report").Visible = xlVeryHidden
If ActiveWorkbook.ReadOnly Then
Application.DisplayAlerts = False
Else
ActiveWorkbook.Save
End If
End Sub
Instead of Application.DisplayAlerts = False, I have also used ThisWorkbook.Saved=True
Thanks