Help making a loop end

gschwint

Board Regular
Joined
Aug 17, 2004
Messages
121
I have the following code set to run before a workbook close event and it never gets out of the loop:

Code:
Sub HideSheets()
Dim sht As Object
Dim saveresponse As Boolean

Application.ScreenUpdating = False

ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVisible

For Each sht In ThisWorkbook.Sheets

If sht.Name <> "Macros Disabled" Then sht.Visible = xlSheetVeryHidden

Next sht

Do Until saverespone = True
MsgBox "You Must save a copy of this file before exiting the spreadsheet otherwise it may not function correctly when opening the spreadsheet again." & vbNewLine & vbNewLine & "This may up to 1 minute or more depending on your computer speed.", vbCritical, "Saving the File is Required"
saveresponse = Application.Dialogs(xlDialogSaveAs).Show
Loop

Application.Quit

End Sub

Any help?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Ciao gschwint,
if the use of the loop with the syntax

Do Until saverespone = True
...
Loop


is not mandatory, you can use the following:
...
Do While Not saveresponse
saveresponse = False
Do While Not saveresponse
MsgBox ...
saveresponse = Application.Dialogs(xlDialogSaveAs).Show
Loop
...

:p :p
 
Upvote 0
I had to add an additional "loop" to the bottom of the code but after that it worked like a charm. Thanks much.

George
 
Upvote 0

Forum statistics

Threads
1,214,963
Messages
6,122,484
Members
449,088
Latest member
Melvetica

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