thanks hank.
but that is not the information that i need.
I think you need to clarify exactly what information it is that you DO
need; your actual question was "what syntax do u use to make the kill
command destroy the file selected?", and that would indeed be
Kill "C:\programs\mycrap\test.xls"
Taking another guess at what you need, and assuming that the list is a
Control Toolbox combo box, you could use the combo box's Change event
to drive the deletion based on the user's selection. Like so:
Private Sub filetodestroy_Change()
Dim s_FileDir As String
Dim l_mbresp As Long
'Check that there's a selection.
If filetodestroy.ListIndex <> -1 Then
'Confirm that the file still exists.
s_FileDir = Dir(filetodestroy.Text)
If s_FileDir = "" Then
MsgBox "The file " & filetodestroy.Text _
& " no longer exists.", vbInformation
'Don't want this triggering another change event.
Application.EnableEvents = False
'Remove the non-existent file from the list and
'clear the entry.
With filetodestroy
.RemoveItem filetodestroy.ListIndex
.Text = ""
End With
Application.EnableEvents = True
Else
'If the file DOES exist, confirm that we want
'to delete it.
l_mbresp = MsgBox("Are you sure that you want to delete file "
_
& filetodestroy.Text & "?", vbYesNo + vbDefaultButton2)
If l_mbresp = vbYes Then
Kill filetodestroy.Text
Application.EnableEvents = False
With filetodestroy
.RemoveItem filetodestroy.ListIndex
.Text = ""
End With
Application.EnableEvents = True
End If
End If
End If
End Sub
On the other hand if you don't want to drive the deletion straight off
the selection and want to just read the file name from the list box
(so that some other code can delete it), then filetodestroy.Text would
get you the name to feed to the Kill statement.
If that's not it, please clarify.