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....
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,518
Messages
5,596,630
Members
414,082
Latest member
sasmita

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