After 11 years Word is still holding a lock on the original .doc after using .SaveAs (.SaveAs2)

Pino Carafa 121 Reputation points
2021-03-27T13:23:39.73+00:00

I see that this issue was already raised at least 11 years ago:

https://social.msdn.microsoft.com/Forums/en-US/ab69e025-8aac-4349-8aef-703c4608b3eb/cant-delete-file-after-renaming-due-to-word-file-handle-still-present-error-staes-document-is?forum=isvvba

My own situation is slightly different, but it's the same underlying issue.

I open a Word.Document in a .NET application. The Word.Document happens to be referencing an old style ".doc" rather than a ".docx"

Once it's opened, I use .SaveAs2 to save a copy of this document to a new location.

At that point I need to copy another file to the original location.

This fails because even after the .SaveAs2 which saved the document to a new location, Word still holds a lock on the original .doc

The problem doesn't arise with .docx documents. Nor does it arise with .xls workbooks (using the equivalent Excel objects). Only in Word.

And no, I can't code around it. The .doc is opened by one application, while our Add-in is trying to then use SaveAs2 to copy it to another location. At this point the document is already open and I cannot close it because the calling application holds a handle to the Word.Document.

Yes, I can code around it by modifying the original application. Simply let it convert the .doc to a .docx and then present it to the user. But that requires a new version of the original application. Our users are fickle beasts. Some of them want to be able to use the OLD application with the NEW addin. And the only thing preventing us from giving them that option is this issue.

Like I said. This was already reported to Microsoft at least 11 years ago. Who knows how long people have faced similar issues before that.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,489 questions
Office Management
Office Management
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Management: The act or process of organizing, handling, directing or controlling something.
2,000 questions
Word Management
Word Management
Word: A family of Microsoft word processing software products for creating web, email, and print documents.Management: The act or process of organizing, handling, directing or controlling something.
893 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Stefan Blom 2,061 Reputation points MVP
    2021-03-27T14:07:15.73+00:00

    When you use Save As on a document in *.doc format, the owner/lock file (whose name starts with ~$) will be retained even after the save. That is why Word thinks the file is in use. This can easily be reproduced even without code, using the Save As interface in Word. See attached screen shot. 81990-retainedlockfileexample.png

    You can report it to Microsoft, but my guess is that it will have low priority, because we are expected to use the *.docx format.