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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

chiello

Well-known Member
Joined
Jan 18, 2005
Messages
848
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
 

gschwint

Board Regular
Joined
Aug 17, 2004
Messages
121
I had to add an additional "loop" to the bottom of the code but after that it worked like a charm. Thanks much.

George
 

Forum statistics

Threads
1,147,510
Messages
5,741,574
Members
423,668
Latest member
Audorin

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