#1
|
|||
|
|||
KILL errors RTE 70
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. |
#2
|
|||
|
|||
Greg hat happens if you comment out "Documents.Open strNewName"?
|
#3
|
|||
|
|||
Kilroy,
No difference. Actually it doesn't even hit that line during batch folder processing. Just this: oDoc.Close 0 DoEvents If .chkMatchWildCards.Value = True Then Kill strTempName Works perfectly fine in later versions of Word. |
#4
|
||||
|
||||
The issue here relates to how you are converting the document (which is not shown in your example) and the reason you cannot kill the file is that it is held open by the lock file. If you look at the folder with the hidden files diplayed at the point of crashing you will see lock files for both the DOT file and the new DOTM/X file.
If you use a method similar to that shown below, the problem does not occur: Code:
Sub Macro1() Dim strTempName As String Dim oDoc As Document Dim oNewDoc As Document Dim strNewName As String Set oDoc = ActiveDocument strTempName = oDoc.FullName If Right(LCase(oDoc.Name), 3) = "dot" Then If oDoc.HasVBProject Then strNewName = oDoc.FullName & "m" oDoc.SaveAs2 _ FileName:=strNewName, _ FileFormat:=wdFormatXMLTemplateMacroEnabled, _ CompatibilityMode:=Val(Application.Version) Else strNewName = oDoc.FullName & "x" oDoc.SaveAs2 _ FileName:=strNewName, _ FileFormat:=wdFormatXMLTemplate, _ CompatibilityMode:=Val(Application.Version) End If End If oDoc.Close 0 DoEvents Kill strTempName Set oDoc = Documents.Open(strNewName) End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Graham,
No joy. Here the file you sent back that works with your Word 2007, still throws the runtime error at the Kill statement. The culprit is a lingering ~$ file lock. I even added code to loop through the folder, look and delete lingering ~$ locks. It does, but the error still occurs. Not just me because I got to looking this due to feedback on our BatchProcessDocuments Add-In. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Kill the file based on date | Villalobos | Word VBA | 9 | 07-06-2017 09:50 PM |
Odd errors | cyberslugg | PowerPoint | 2 | 02-23-2016 01:26 PM |
Need Help With KILL Command | PosseJohn | Word VBA | 1 | 12-09-2013 03:32 PM |
"One or more margins are set outside the printable area of the page." How to kill? | WaltR | Word | 4 | 07-16-2012 01:55 PM |
Help! What Are These & How Do I Kill Them? | Finn O'Deirg | Word | 2 | 07-03-2012 01:54 PM |