View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach[_2_] Otto Moehrbach[_2_] is offline
external usenet poster
 
Posts: 1,071
Default Error in a "Kill" command

Rick
The path does end in a backslash. Dave pointed out that the word
"Workbooks" and a Word file name (xxx.doc) do not go together, and that's
obvious now that he has pointed it out.
I have 3 Word files, none of which are open, and I want to remove them
from disk (hence the Kill command). Any help you can provide with the code
would be appreciated. Thanks again. Otto
"Rick Rothstein (MVP - VB)" wrote in
message ...
I'm do not see why you have to change the file access to Read Only in
order to delete it, but that shouldn't be your error either. My first
thought is that ThePathDocs variable does **not** end in a backslash (so
that when you concatenate it with TheFile, the resulting filename is an
ugly combination of the last folder in the path and the actual filename).

Rick


"Otto Moehrbach" wrote in message
...
Excel XP & Win XP
In this snippet of code I am trying to "Kill" 3 files. I get a
"Subscript out of range" error on the "Kill" command with the first file.
So I changed the order of the files in the "For Each.." line and again I
get that error with the first name. This tells me that the problem is
with the "Kill" line. The "ThePathDocs" is the path to the folder that
holds the files. What did I do wrong? Thanks for your time. Otto

For Each TheFile In Array("One.doc", "Two.doc", "Three.doc")
Workbooks(ThePathDocs & TheFile).ChangeFileAccess xlReadOnly
Kill Workbooks(ThePathDocs & TheFile).FullName