In Excel press Alt + F11 to enter the VBE. Press Ctrl + R to show the Project Explorer. Right-click desired file on left (in bold). Choose Insert -> Module. Paste code into the right pane. Press Alt + Q to close the VBE. Save workbook before any other changes. Test the code: Enter some data on the worksheet. In this article we will learn how to excel close workbook using VBA in Microsoft Excel 2010. After your VBA macro / code has performed all the required actions, you would want the macro to either save the file or skip saving it. So here are the options you can set in the code while asking it to close the file.
Imagine you had been working on a really important Workbook for hours and the system crashes. The file is not saved, and you just lost hours of work because you forget to hit the save button. But what about when you realize that you made a mistake while working on the workbook an hour ago? How do you go back to an older version of the Excel file? Well, don’t panic because we have compiled together some of the most efficient tips to recover unsaved Excel files and their older versions. By default, Microsoft provides an AutoRecovery option which can recover files that were saved, but their latest version cannot be accessed because the system or Excel crashed.
Configure the AutoRecover Settings in Excel. Go to the File tab and click on Options. Click on the Save tab. Make sure both ‘Save AutoRecover information every Z minutes’ and Keep the last autosaved version if I close without saving’ are checked. You can also keep the autorecover duration to the smallest to make sure every file is saved.
Click on OK After this, whenever you open Excel after a crash, you will be able to see the files that can be autorecovered. But, this only applies to files that have been saved at least once. For files that haven’t been saved at all, follow the steps in the next section. Recover unsaved Excel file In order to recover an Excel file that you forget to save, follow the steps below. Go to the file tab and click on ‘Open’. Now click on the Recent Workbooks option on the top left.
Now scroll to the bottom and click on ‘Recover Unsaved Workbooks’ button. Scroll through the list and search for the file you lost. Double-click on it to open it. The document will open in Excel, now all you have to do is hit the Save As button Recover overwritten Excel files If you are using Excel 2010 or 2013, then you can easily recover an older version of the document. It is extremely helpful if you made a mistake on the Workbook and realized it late or you just want to see what the workbook looked like before.
To do this, here are the steps you need to follow. Click on the File tab and select Info. Now click on the manage versions tab. There you will be able to see all the versions that were autosaved by Excel But you can also see these autosaved versions until you have saved the file. Once the current version of the file has been saved, all the previous autosaved files will disappear.
To save them, you need to take the backup of the file. Saving a backup of Excel file Taking a backup of Excel files makes it possible to revisit older versions in case you made a mistake. This can be useful when you hit the save button when you didn’t mean it or when you delete the main original final. Here is how you can take a backup in Excel 2010 and 2013. Go to the File tab and click on ‘Save as’.
Now click on the Browse tab at the bottom. A Save as window will open up. At the bottom of it, there is an option called Tools. Click on Tools and select ‘General options’. In the new Window, check on ‘Always create backup Now every new Excel file that you create will have a backup file associated with it.
But remember that backup Excel files have a different extension –.xlk Overall, it’s very easy to even when you forgot to save them. All you have to do is not panic and follow the steps we mentioned.
Please do as follows to save and close an active workbook without prompt by a Command Button in Excel. Click Developer Insert Command Button (ActiveX Control), then draw a Command Button in your worksheet. See screenshot: 2. Right click the Command Button, and click View Code from the right-clicking menu. Then the Microsoft Visual Basic for Applications window pops up, please replace the original code in the Code window with below VBA script. VBA code: Save and close workbook by Command Button Private Sub CommandButton1Click Application.Quit ThisWorkbook.Save End Sub Note: In the code, CommandButton1 is the name of your inserted Command Button.
Press Alt + Q keys simultaneously to quit the Microsoft Visual Basic for Applications window. Turn off the Design Mode under the Developer tab. From now on, when clicking the Command Button, the active workbook will be saved and closed automatically without prompt.
Related articles:. Increase your productivity in 5 minutes.
Don't need any special skills, save two hours every day! 300 New Features for Excel, Make Excel Much Easy and Powerful:. Merge Cell/Rows/Columns without Losing Data. Combine and Consolidate Multiple Sheets and Workbooks. Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion. Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,.
More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools.