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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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
 
Upvote 0
You can try something like this:

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

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

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