Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to cancel out of an Excel dialog box?

Status
Not open for further replies.

Quintios

Technical User
Mar 7, 2002
482
US
I have the following code to select a save location for a workbook:

Code:
    Application.Dialogs.Item(xlDialogSaveAs).Show arg1:="sheet1", arg2:=xlCSV

    ActiveWorkbook.Saved = True
    ActiveWindow.Close

If the user hits the cancel button, how do I detect this and exit out of the macro? Right after that I have the code that closes the workbook and I'd like to exit out if the user hits cancel.

Thanks in advance for your help!
Onwards,

Q-
 
Try changing it to this, If the user clicks Cancel the Dialog returns as false else its true.

If Application.Dialogs.Item(xlDialogSaveAs).Show("Sheet1", xlCSV) = False Then

exit sub
else
ActiveWorkbook.Saved = True
ActiveWindow.Close
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top