
Tips.Net > WordTips Home > Files > Deleting the Open Document File
Summary: Want to delete the document you are currently viewing? Word doesn’t provide a way to do it, but you can use the macro in this tip to make the task easy as pie. (This tip works with Microsoft Word 97, Word 2000, Word 2002, Word 2003, and Word 2007.)
Periodically, I go through the files in my Word directories to determine if any of the old documents can be safely deleted. Many times, I need to open the file to examine it before I can make a determination as to whether it should be deleted.
Of course, Word will let you delete a file listed in the Open or Save dialog boxes, but it will not delete the active document—the one that is open at the current time. Rather than close the active document and then delete it by opening the Open or Save dialog boxes, I use the following macro to delete a file which is open.
Sub DeleteThisFile()
Dim MyFile As String
MyFile = ActiveDocument.Path & "\" & ActiveDocument.Name
If MsgBox(MyFile & " will be deleted permanently", _
vbYesNo, "Delete this File?") = vbYes Then
ActiveDocument.Close (wdDoNotSaveChanges)
Kill MyFile
End If
End Sub
The macro prompts you to make sure that you want to delete the file, and (if you do) it closes the document without saving and then deletes it. You should note that the file will not go to the Recycle Bin, but will be immediately deleted.
Tip #1346 applies to Microsoft Word versions: 97 2000 2002 2003 2007
Great Idea! Uncover the many ways you can master the full potential of printing your documents. WordTips: Printing and Printers can help you get the most from both the printed page and your printer.
Word includes two powerful search engines. Do you know how to use them both? You can discover new knowledge with WordTips: Find and Replace. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Pet Tips
Word2007 Tips
WordTips