Infinite save prompt loop on close

MoshiM

Active Member
Joined
Jan 31, 2018
Messages
439
Office Version
  1. 2016
Platform
  1. Windows
I'm using the following macro to suppress messages about there being things within the workbook that the document inspector can't remove. It works but when closing the file it enters an infinite loop of saving and then prompting me if I want to save changes.

How could I exit this loop after the first time it pops up?
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)


    With Application


        .DisplayAlerts = False : .EnableEvents = False


        ThisWorkbook.RemovePersonalInformation = True


        ActiveWorkbook.Save


        .EnableEvents = True : .ScreenUpdating = True : .DisplayAlerts = True


    End With


    ThisWorkbook.Saved = True


    Cancel = True


End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Do you have any code in a beforeClose event?
 
Upvote 0
If I save the file & then close it, I don't get any problems.
 
Upvote 0
If I save the file & then close it, I don't get any problems.
Still an infinite loop for me. I also tried adding a Thisworkbook.saved=True to my afterSave event as well
 
Upvote 0
Try putting that line in the BeforeClose Event
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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