View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Error in a "Kill" command

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Otto Moehrbach" wrote in message
...
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
"Don Guillett" wrote in message
...
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.
Maybe you need to just set the path and kill that.
Or, maybe just change to

Kill ThePathDocs & TheFile.FullName

Sub KillFile()
mc = Choose(ActiveCell.Column, 4, 3, 2, 1, 0)
wbn = ActiveCell.Offset(0, mc).Value
MyAnswer = MsgBox("Do you want to KILL this file?", vbYesNo)
If MyAnswer = vbYes Then
Kill wbn
ActiveCell.EntireRow.Delete
End If
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"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