Infinite save prompt loop on close

MoshiM

Active Member
Joined
Jan 31, 2018
Messages
370
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
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,728
Office Version
  1. 365
Platform
  1. Windows
Do you have any code in a beforeClose event?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,728
Office Version
  1. 365
Platform
  1. Windows
If I save the file & then close it, I don't get any problems.
 

MoshiM

Active Member
Joined
Jan 31, 2018
Messages
370
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,728
Office Version
  1. 365
Platform
  1. Windows
Try putting that line in the BeforeClose Event
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,728
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,122,168
Messages
5,594,632
Members
413,919
Latest member
ZaxAlchemist

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
Top