Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-08-2019, 07:53 AM
gmaxey gmaxey is offline KILL errors RTE 70 Windows 10 KILL errors RTE 70 Office 2016
Expert
KILL errors RTE 70
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default 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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 10-08-2019, 08:50 AM
kilroy kilroy is offline KILL errors RTE 70 Windows 10 KILL errors RTE 70 Office 2016
Competent Performer
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 118
kilroy is on a distinguished road
Default

Greg hat happens if you comment out "Documents.Open strNewName"?
Reply With Quote
  #3  
Old 10-08-2019, 04:02 PM
gmaxey gmaxey is offline KILL errors RTE 70 Windows 10 KILL errors RTE 70 Office 2016
Expert
KILL errors RTE 70
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 10-09-2019, 10:40 PM
gmayor's Avatar
gmayor gmayor is offline KILL errors RTE 70 Windows 10 KILL errors RTE 70 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #5  
Old 10-11-2019, 05:07 AM
gmaxey gmaxey is offline KILL errors RTE 70 Windows 10 KILL errors RTE 70 Office 2016
Expert
KILL errors RTE 70
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
KILL errors RTE 70 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
KILL errors RTE 70 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
KILL errors RTE 70 Help! What Are These & How Do I Kill Them? Finn O'Deirg Word 2 07-03-2012 01:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft