Office Watch

Office 2013

Office Mobile / iPad

Office 2010

Office 2007

Office 2003

Office XP

Office for Mere Mortals



Buying Office

Office 365


Office News Wire

Join us!

Our Ebooks

Mobile | PDA



Command Finder

Microsoft Office Bookshop



Delete an open Word document

Here's how to delete the Microsoft Word document you’re currently editing.

View this page on the new web site - click here

by Rose Vines

Bookmark and Share

  | Mobile | click for more article services     

View this page on the new web site - click here

Here's a rather more complex macro you might find useful. This one lets you delete the document you're currently editing. Word normally won't let you do this: you must first close the document, then delete it. That's a sensible safeguard, but sometimes it gets in the way of what you want to do. I find this macro particularly useful when I want to clean out a whole bunch of old documents: I open each one, check the contents and, if I no longer need it, delete it on the spot.

Because you cannot undelete any document you eliminate using this macro, it takes some preliminary precautions:

  • First, the macro checks that there is, in fact, an open document to delete.
  • If there is an open document, it checks that the user really wants to delete it. If not, the macro ends without doing anything else.
  • If the user gives the go ahead to delete the document, the macro checks to see whether the open document has already been saved. If it has, the document is closed and then deleted. If it has not yet been saved, it is simply closed without saving any changes.

Note that this is the barebones version of the macro code. If you would like to see a fully commented and more readably formatted version of the code you can download a copy from

To create the macro:

1. Press Alt+F8 to open the Macros dialog.

2. Type DeleteActiveDocument in the Name box and click Create.

3. Copy and paste the following code between the Sub DeleteActiveDocument()and the End Sub statements:

Dim strFileToDelete As String
Dim docOpen As Document
Dim intDocCount As Integer
intDocCount = 0
For Each docOpen In Documents
intDocCount = intDocCount + 1
Next docOpen
If intDocCount > 0 Then
If MsgBox("Are you sure you want to delete the open document permanently? " & _
"You won't be able to undo this action.", vbYesNo) = vbYes Then
If Len(ActiveDocument.Path) <> 0 Then
strFileToDelete = ActiveDocument.FullName
ActiveDocument.Close SaveChanges:=False
Kill strFileToDelete
ActiveDocument.Close SaveChanges:=False
End If
End If
MsgBox "There is no open document to delete.", vbOKOnly
End If

4. Close the Visual Basic editor.

To make the macro easily accessible, add it to the Quick Access Toolbar in Word 2007:

1. Click the arrow at the right end of the Quick Access Toolbar and select More Commands.

2. In the Choose Commands From box, select Macros from the drop-down list.

3. Click the newly created macro (it's full name is Normal.NewMacros.DeleteActiveDocument) and then click the Add button.

4. Click the Modify button, select an appropriate icon for the macro (there's a handy one with a cross in a red circle that fits well), type Delete This Doc in the Display Name box and click OK.

To add the macro to a Word 2003 toolbar:

1. Right-click any toolbar and click Customize.

2. On the Commands tab in the Categories list click Macros.

3. Locate Normal.NewMacros.DeleteActiveDocument in the Commands list and click-and-drag it onto a toolbar.

4. Right-click the new button you've created, in the Name box type Del (or something else short and descriptive), then click Text Only. If you'd prefer to use a graphic icon instead of a text-label, although none of the default icons is particularly apt you can create your own by selecting Default (instead of Text Only). Then click Edit Button Image, then Clear and then do a quick paint job (a red X works well).

5. Click Close in the Customize dialog box.

If you have any problems running the macro, take a look at the code in the Visual Basic editor and make sure you don't have any broken lines. That's the most common cause of problems.

Article posted: Thursday, 17 July 2008

View this page on the new web site - click here

there's more ...

If you liked this article you'll LOVE our new ebooks.

Office 2013: the real startup guide

OFFICE 2013: the real startup guide Everything you need to know about Office 2013 but Microsoft won't tell you.

How to save money, install, configure and use the new features in Office 2013.  Get it today - click here.

Windows 8 for Microsoft Office users

Windows 8 for Microsoft Office users A practical guide the new, changed and unfamiliar in Windows 8

A focused and unvarnished look at Windows 8, especially written for the many people who use Microsoft Office  Get it today - click here.

ORGANIZING OUTLOOK EMAIL - tame your Outlook 2010 Inbox

100+ pages of practical tips and help to streamline, automate and search your Inbox.  Get more than you ever thought possible from Outlook.  Read it today - click here.

More from Office Watch:

Article Services sponsored by: Office Watch Ebooks - available now to download and read today.
RSS feed for this category Subscribe

Translate | Mobile | Links
 Add to: Bookmarks | | DiggThis | Yahoo! My Web

New & Popular
» New web site
» Two ways for sorting by Number
» Office for iPad, September updates
» Why is Gene Cernan ignored in Word?
» DropBox prices drop but is it enough?
» Sort by hidden column in Word

Office Watch, Office for Mere Mortals, Access Watch and all titles used within the publications are Copyright © 1996-2014 Office Watch.
Microsoft Office, Microsoft Word, Microsoft Excel, Microsoft Outlook, Microsoft Powerpoint and doubtless many other names are registered trademarks of Microsoft Corporation.

Search  |  Sitemap |  Popular Topics | Privacy Statement |  Advertising |  Twitter |  Feedback / Contact Us
Office Watch is definitely not affiliated with Microsoft - and that's just one reason why we are so useful to Microsoft Office users around the world J (Erko).