Jump to content

delete an open word document directly

Recommended Posts

HEY, all

Recently I want to clean my working folders. And for most of the word file, I have to open them to check if it's still useful to me. But if I want to delete it, I need to close it and then delete it.

As there are so many files which are waiting to be checked, I'm thinking if I can get a "delete" button in word , just like "Save" button. So I can click on the "delete" button to delete the open file directly without closing it. It will save much time for me.

How can I do this??


Share this post

Link to post
Share on other sites

By default you can't delete any file which is in use.

No matter it's a Word file or any other file.

Share this post

Link to post
Share on other sites

Actually you can't do that directly, but you can use VBA  as alternative.

Here is a macro I get. You can try:

Sub DeleteOpenDoc()
  Dim objDoc As Document
  Dim strDocName As String
  Dim strButtonValue As String
  '  Initialization
  Set objDoc = ActiveDocument
  strDocName = ActiveDocument.FullName
  '  Check if the doc has beed saved.
  If objDoc.Path = "" Then
    MsgBox ("This document hasn't been saved.")
    Exit Sub
  End If
  '  Deletion confirmation
  strButtonValue = MsgBox("Are you sure to delete " & strDocName & "?", vbYesNo)
  If strButtonValue = vbYes Then
    objDoc.Close SaveChanges:=wdDoNotSaveChanges
    KillFile = strDocName
    Kill KillFile
  End If
End Sub

And more details, you can see at


Good luck

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.