View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
charles charles is offline
external usenet poster
 
Posts: 124
Default kill command and excel

thank you for taking the time to respond.

"JLatham" wrote:

Well, I suppose you could use something like
Kill filetodestroy.Text

Or you might be able to make use of this code which allows you to select a
file using the file picker dialog, and in this case, Kill the file selected:

Sub KillAFile()
Dim Response As String
Response = SelectFileForUse()
If Response < "" then
Kill Response
End If
End Sub

Function SelectFileForUse() As String
'either return a full well-formed path & filename
'to file selected, or "" if user cancels.
'
Dim fd As FileDialog
Dim vrtSelectedItem As Variant

'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)

With fd
If .Show = -1 Then
'user chose a file
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is a String that contains the path of each selected
item.
'You can use any file I/O functions that you want to work with this
path.
SelectFileForUse = vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
SelectFileForUse = ""
End If
End With

Set fd = Nothing ' good housekeeping
End Function

"charles" wrote:

thanks hank.
but that is not the information that i need.

I want to be able to select the file that i want destroyed from a list of
files in a drop down box. And have the kill command destroy the file that is
selected in the drop down box. The drop down box name is "filetodestroy"

"Hank Scorpio" wrote:

On Sat, 29 Aug 2009 17:35:01 -0700, charles
wrote:

I would like to use the Kill command to delete a file whose name and location
have been selected in a drop down box.

ie the drop down box named "filetodestroy" has the following selected
C:programs/mycrap/test.xls

what syntax do u use to make the kill command destroy the file selected?

It's just
Kill pathname

but at a guess your problem is that it should be
C:\programs\mycrap\test.xls

(That is, you're missing the first slash after the drive. Generally
the path will use backslashes rather than forward slashes as well,
though either will work with Kill.)

You may also want to use
On Error Resume Next
before the command and
On Error GoTo 0
after it to temporarily turn off error handling. That way if the file
isn't there, you won't be bugged with an error message.