Shared workbook & save without prompt on close

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
196
Hi

I have this code;
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wsSheet As Worksheet
    For Each wsSheet In Worksheets
        wsSheet.Visible = xlSheetVisible
        If wsSheet.Name <> "Cover Page" Then
           wsSheet.Visible = xlSheetVeryHidden
        End If
    Next wsSheet
    If ThisWorkbook.Saved = False Then
        ThisWorkbook.Save
    End If
End Sub

The challenge I have is around prompts on saving. If person A and person B are in the shared book, and, person A closes the book then the above code works fine. If person B then closes the book, the save prompt still appears (but the above code says to save if not saved so not sure why this is happening).

I recognize (from my own learning on the topic so far) that between person A closing and person B closing, that things have happened in the background hence the prompt to save. However, is there a way around this so that it saves regardless / on every time without prompt?

Any help would be massively appreciated.

Thanks
Ben
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Maybe!

It works fine if in a 'non-shared' workbook or for the first person to close the shared workbook down. It's just if subsequent users close the workbook, does the save prompt appear.

If the statement is forcing the save question, I'd imagine it would force it in the above 2 examples as well? Feel like I'm missing something
 
Upvote 0
Not sure if this works with shared workbooks, but try
Code:
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top