OPTION TO SAVE OR CANCEL

Fimwizard

New Member
Joined
Mar 1, 2004
Messages
7
I have created a code that will have a couple of messages and then call for the SaveAs window. But, I would like to put a code that if the user cancels, the routine would stop and return to the workbook. So far I got to work if he saves, but even if I cancel it still runs. The code looks something like this. Any ideas?

'
MsgBox ("You are about to Archive Pay Period"), vbExclamation
'
MsgBox ("All records are about to be Archived"), vbOKCancel
'
' HERE I WOULD LIKE TO PUT THE CODE TO BAIL OUT IF CANCEL
'
Application.Dialogs(xlDialogSaveAs).Show
'
'
Sheets("Week 1").Select
Range("B12:J50").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("B12").Select
Sheets("Week 2").Select
Range("B12:H50").Select
Selection.ClearContents
Range("B12").Select

ECT....
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Fimwizard

New Member
Joined
Mar 1, 2004
Messages
7
OPTION TO SAVE OR CANCEL
I have created a code that will have a couple of messages and then call for the SaveAs window. But, I would like to put a code that if the user cancels, the routine would stop and return to the workbook. So far I got to work if he saves, but even if I cancel it still runs. The code looks something like this. Any ideas?

'
MsgBox ("You are about to Archive Pay Period"), vbExclamation
'
MsgBox ("All records are about to be Archived"), vbOKCancel
'
' HERE I WOULD LIKE TO PUT THE CODE TO BAIL OUT IF CANCEL
'
Application.Dialogs(xlDialogSaveAs).Show
'
'
Sheets("Week 1").Select
Range("B12:J50").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("B12").Select
Sheets("Week 2").Select
Range("B12:H50").Select
Selection.ClearContents
Range("B12").Select

ECT....
_________________
Marco Gonzalez
 

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
You can try something like this:

If MsgBox ("All records are about to be Archived",vbOkCancel)=vbCancel Then
Exit Sub
End If
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,954
Messages
5,856,493
Members
431,818
Latest member
AKEMAROD

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