6

Click here to load reader

AutoSave Excel before Exit

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: AutoSave Excel before Exit

Auto-Save Excel before Closing

Date: 14/May/2012

Author: sevenSolutions

About: Creating a tiny macro in Excel that will auto

save the file when the user closes the file.

Page 2: AutoSave Excel before Exit

Auto Save Excel as you Exit May-2012

2 [email protected] | www.sevensolutions.in | +91 7503 03 3057

Assumption: You already have an Excel-2007 file that you want to auto-save when you click on or when

you do a:

>> .

1: Click on “Developer” tab and then click on “Visual Basic”.

2: You will reach the below screen. Double-Click on “ThisWorkbook”.

Page 3: AutoSave Excel before Exit

Auto Save Excel as you Exit May-2012

3 [email protected] | www.sevensolutions.in | +91 7503 03 3057

3: The “ThisWorkbook” page would open, with “General” and “Declaration” pull-down boxes on top.

4: Pull down the box saying “General” and chose “Workbook”. It would change the “Declaration” to say “Open” and

auto-fill the workspace with some codes as below:

Page 4: AutoSave Excel before Exit

Auto Save Excel as you Exit May-2012

4 [email protected] | www.sevensolutions.in | +91 7503 03 3057

5: Pull down the Box saying “Open” and choose “BeforeClose”. It would auto-fill the workspace with more codes,

as below:

6: In the new code snippet that appeared above { Workbook_BeforeClose (Cancel As Boolean) }, write the below

line of code:

ActiveWorkbook.Save

It should look like below:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

ActiveWorkbook.Save

End Sub

See the below image.

Page 5: AutoSave Excel before Exit

Auto Save Excel as you Exit May-2012

5 [email protected] | www.sevensolutions.in | +91 7503 03 3057

7: Save the Workbook and the Code by clicking on the save button and it will ask you to save it. You would beed to

save it in “.xlsm” format, because Excel 2007 allows Macro to be saved in “.xlsm” format only, not in “.xlsx”

format. It is simply for Excel 2007 to know that in this Excel file you are going to write codes in Visual Basic.

8: If you try to “Save As” the replacing your existing one (which I am assuming is a .xlsx file), it would give you the

following message. If you chose Yes, Excel will delete the codes. So, chose to save in .xlsm format.

Page 6: AutoSave Excel before Exit

Auto Save Excel as you Exit May-2012

6 [email protected] | www.sevensolutions.in | +91 7503 03 3057

So now, whenever you close this Excel file, you do not have to worry about whether you have Saved the file or not.

Before closing, excel will automatically save the file.

For any questions regarding this file, or help in creating an Auto Saving file for you, or to create any magic in Excel

using Macros, do not hesitate to [email protected] or call at +91 7503 03 3057!

Thanks.

Like | Follow | Email | Visit | +91 7503 03 3057