I have an add-in for processing batch files in a selected folder. One of the built-in batch processes converts older .doc and .dot format files as .docx, .docm, .dotx or .dotm as appropriate.
It basically just opens the file and saves it in a new format then deletes the old .doc or .dot file.
It works fine with Word 2010-2019. And it "almost" works with Word 2007. However, it won't delete the old file. It errors on the Kill statement below with RTE 70. Permission Denied (other attempts e.g., FileSystemObject also result in RTE 70).
Code:
Case "Convert older format documents"
strTempName = oDoc.FullName
If Right(LCase(oDoc.Name), 3) = "dot" Then
mod_Convert.ConvertFiles oDoc, oDoc.Path, True
Else
mod_Convert.ConvertFiles oDoc, oDoc.Path, False
End If
If .optActiveDocument Then
If .chkMatchWildCards.Value = True Then
strNewName = oDoc.FullName
oDoc.Close 0
DoEvents
Kill strTempName
Documents.Open strNewName
End If
Else
oDoc.Close 0
DoEvents
If .chkMatchWildCards.Value = True Then Kill strTempName
End If
The file is not open but Windows seems to think it is. If I close Word and then reopen Word, I can then delete the file with a simple Kill statement.
I have tried:
SetAttr strTempName, vbNormal
Does anyone know how to force Windows to "rethink" the state of a file that is not opened and allow the Kill to proceed without error?
Thanks.