Nubee with an AutoSave question.

Nick54

New Member
Joined
Mar 27, 2009
Messages
40
Would someone please explain how to upon selecting the "X" in the upper right corner of a worksheet or by selecting "File" - "Exit" force to the first tab in the workbook and then auto save?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this in the ThisWorkbook module

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets(1).Select
Me.Save
End Sub
 
Upvote 0
Peter,

I have just used the VBA you posted yesterday and it works fine.

How would I amend it to auto save sheet 1 & 2, I have tried a few combinations but none seem to work.

Craig.
 
Upvote 0
That should save the entire workbook. Or do you mean save those sheets as a new workbook?
 
Upvote 0
Thanks for that Peter, I assumed wrongly that when you stated

Sheets(1).Select

in the code I thought it would only save sheet 1 and not the whole workbook.
Trying it shows me it just selects sheet 1 on saving. Am I correct in this thought?

Craig.
 
Upvote 0
Here is what I did with the code you provided.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets(INSTRUCTIONS).Select
Me.Save
End Sub

Sheet 1 was remaned to INSTRUCTIONS

I know I'm likely not using your code correctly but after colssing trhe spreadsheet and re-opening I am on the page I closed it from.
 
Upvote 0
It should be

Rich (BB code):
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("INSTRUCTIONS").Select
Me.Save
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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