
Signature
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com
Don
Thanks for your help. I understand that one must set the file attribute
to "Read Only" prior to "killing" the file. Is that true? Otto
> This is a sub I use to kill a file where the full path is typed into a
> cell along with some other stuff in the same row.
[quoted text clipped - 24 lines]
>> Workbooks(ThePathDocs & TheFile).ChangeFileAccess xlReadOnly
>> Kill Workbooks(ThePathDocs & TheFile).FullName
Chip Pearson - 17 Mar 2008 02:15 GMT
I believe you do in fact need to change access to read-only. Otherwise
you'll get a "permission denied" error.

Signature
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
> Don
> Thanks for your help. I understand that one must set the file
[quoted text clipped - 28 lines]
>>> Workbooks(ThePathDocs & TheFile).ChangeFileAccess xlReadOnly
>>> Kill Workbooks(ThePathDocs & TheFile).FullName
Dave Peterson - 17 Mar 2008 02:24 GMT
Nope.
In fact, if you set the attribute to readonly, then you'll have trouble deleting
the file.
The code that you tried to use is based on code that deletes a workbook that's
open in excel. If the file is open in read/write mode, then windows will yell
at you when you try to delete it (either manually or via code).
The .changefileaccess line doesn't change the file's attribute. Instead, it
tells excel to change its access to that file as readonly. Kind of like
originally opening the file in readonly mode.
Then Windows won't see the file/workbook as in-use and the Kill statement will
work.
====
Some notes about your original code:
For Each TheFile In Array("One.doc", "Two.doc", "Three.doc")
Workbooks(ThePathDocs & TheFile).ChangeFileAccess xlReadOnly
Kill Workbooks(ThePathDocs & TheFile).FullName
This doesn't really make sense to me. The file extensions are .doc. I would
think that you would not have this kind of file open in excel.
That means that you would refer to them through the workbooks() collection.
If your code were using excel files and these files were open, you could use:
For Each TheFile In Array("One.xls", "Two.xls", "Three.xls")
Workbooks(TheFile).ChangeFileAccess xlReadOnly
Kill Workbooks(TheFile).FullName
When you use workbooks(), you don't specify the drive/folder/path--just the
filename.
> Don
> Thanks for your help. I understand that one must set the file attribute
[quoted text clipped - 32 lines]
> >> Workbooks(ThePathDocs & TheFile).ChangeFileAccess xlReadOnly
> >> Kill Workbooks(ThePathDocs & TheFile).FullName

Signature
Dave Peterson
Otto Moehrbach - 17 Mar 2008 18:51 GMT
Dave
Thanks for that. Looking at it again, "workbooks" and ".doc" don't make
any sense to me either. What I have is 3 Word files, none of which are
open. I want to "Kill" them. Then I want to move/copy 3 other word files
from one folder to another. I would appreciate any help you can give with
the code for this. Thanks again for your time. Otto
> Nope.
>
[quoted text clipped - 82 lines]
>> >> Workbooks(ThePathDocs & TheFile).ChangeFileAccess xlReadOnly
>> >> Kill Workbooks(ThePathDocs & TheFile).FullName
Dave Peterson - 17 Mar 2008 19:33 GMT
For Each TheFile In Array("One.doc", "Two.doc", "Three.doc")
kill ThePathDocs & TheFile
next TheFile
assuming that thepathdocs is ok.
> Dave
> Thanks for that. Looking at it again, "workbooks" and ".doc" don't make
[quoted text clipped - 92 lines]
> >
> > Dave Peterson

Signature
Dave Peterson
Otto Moehrbach - 17 Mar 2008 20:33 GMT
Thanks Dave. Otto
> For Each TheFile In Array("One.doc", "Two.doc", "Three.doc")
> kill ThePathDocs & TheFile
[quoted text clipped - 109 lines]
>> >
>> > Dave Peterson
Don Guillett - 17 Mar 2008 13:10 GMT
Here is one in my personal.xls assigned to a custom button on the toolbar. I
use it to kill the worbook that I am currently in. Works if in the set path.
I suppose it could be changed to refer to the dir of the activeworkbook. In
my experience, no readonly needed. Can't remember where it came from.
Sub KillActiveWorkbook()
With ActiveWorkbook
mb = .Name
.Close
End With
MyAnswer = MsgBox("Do you want to KILL this file?", vbYesNo)
If MyAnswer = vbYes Then Kill mb
End Sub

Signature
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com
> Don
> Thanks for your help. I understand that one must set the file
[quoted text clipped - 28 lines]
>>> Workbooks(ThePathDocs & TheFile).ChangeFileAccess xlReadOnly
>>> Kill Workbooks(ThePathDocs & TheFile).FullName