- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to quickly close all workbooks except active one?
In this article, users will learn how to quickly close all workbooks except active ones. Whether users are dealing with a complex project or collaborating with others, mastering VBA code will enhance productivity and simplify the user’s Excel experience. This time-saving method eliminates the need for individually closing each workbook, allowing users to declutter the workspace and minimize distractions This article contains an example that guides users through the process of closing all the workbooks except the active ones.
Example 1: To close all the workbooks except the active one, by using the VBA code in excel.
Step 1
Open an Excel workbook and create a few sample spreadsheets. For the below provided sheet, will be creating 4 such spreadsheets. One can easily view the defined spreadsheets in the sheet tab, as shown below −
Step 2
To understand the processing properly will consider one more workbook, with name De_activate. Sheet is provided below −
Please note that the first provided sheet is considered as active sheet.
Step 3
After that go to the previous sheet, and click on the sheet 2 tab, by using the right click. After that click on the “view code” option. Consider below provided snapshot for proper reference −
Step 4
The above step will open the “Microsoft Visual Basic for Applications”. Consider the below given snapshot for reference −
Step 5
Copy the below given code to the editor −
' define close_all_wrkbok() method Private Sub close_all_wrkbok() ' declaring required variables Dim wrk_book_x As Workbook 'setting the status to screen Application.ScreenUpdating = False ' for each loop For Each wrk_book_x In Application.Workbooks ' if expression to check the active workboook If Not (wrk_book_x Is Application.ActiveWorkbook) Then ' close workbook wrk_book_x.Close ' end of if block End If ' next block Next ' set screen update status to true Application.ScreenUpdating = True ' end of module End Sub
Consider below given a snapshot of data −
Step 7
After that click on the run button shown below −
Step 8
The above step will display a dialog box, that displays the message dialog box “Microsoft Excel”, and click on the “Save” button, as shown below −
Step 9
The above step will automatically close the window.
Conclusion
To close all the workbooks quickly except the active one in Excel is a valuable skill that can significantly improve users’ workflow efficiency. By following the steps demonstrated in this article, users can effortlessly close unnecessary workbooks and maintain focus on the workbook user are currently working on.. Whether the user is managing complex projects or collaborating with others, mastering this method will help the user to streamline the Excel experience and improve productivity. So, take advantage of this efficient approach to quickly close all workbooks except the active ones and enjoy a more organized and focused working environment.