- Trending Categories
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 Delete Active Workbook (Current File) In Excel ?
It's occasionally necessary to delete the file you're working on in Microsoft Excel because it has so many robust tools and capabilities for organising and modifying data. This article will walk you through the procedure step by step, whether you wish to start again or delete superfluous files.
A few straightforward but essential actions are needed when deleting the active workbook in Excel to prevent unintentionally deleting valuable data. It's crucial to remember that this step permanently deletes the file, so it's advised to make a backup or make sure you don't need the workbook anymore before moving forward. We'll go over a number of ways to delete the current workbook in Excel during this article. The methods described here should work with any version of Microsoft Excel, whether you're using the most recent version or an earlier one.
Delete Active Workbook (Current File)
Here we will first create a VBA module and run it to complete our task. So let us see a simple process to know how you can delete an active workbook (current file) in Excel.
Step 1
Consider any Excel sheet. First, right−click on the sheet name and select "View Code" to open the VBA application. Then in the VBA application, click on "Insert" and select "Module.
Right click > View code > Insert > Module.
Step 2
Then copy the below−mentioned code into the text box, similar to the below image.
Code
Sub DeleteActiveWorkbook() Dim xFullName As String xFullName = Application.ActiveWorkbook.FullName ActiveWorkbook.Saved = True Application.ActiveWorkbook.ChangeFileAccess xlReadOnly Kill xFullName Application.ActiveWorkbook.Close False End Sub
Step 3
Then save the sheet as a macro−enabled template and click F5 to run the module, and the active workbook will be deleted.
Note
This VBA can shut down the Excel window but not the active worksheet. After deleting the active workbook, if no new workbooks open, manually close the Excel window.
This VBA cannot delete a worksheet that has never been saved before. But by closing it, you can immediately remove this unsaved workbook.
Conclusion
In this tutorial, we have used a simple example to demonstrate how you can delete an active workbook (current file) in Excel to highlight a particular set of data.