delete a file macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i'd like to write a macro to delete all excel files from my desktop. i've
tried using the record macro option but can't even get it to delete one file.
i was hoping for some kind of wildcard code like statement*.xls. can anyone
help
 
Jnu,

Is your question related to MS Access, the database product? If you are
working in Excel, you may have a better chance of good help if you post
to an Excel-related newsgroup.
 
it's all in excel. i have found this and it is fine except when there are no
files the macro crashes, so now i have a question on how can i get this to
work with or with excel files on my desktop

Dim KillFilePath As String
KillFilePath = "c:\documents and settings\all users\desktop\easy*.xls"
Kill KillFilePath
End Sub
 
You can either specify On Error Resume Next, so that it'll ignore the error,
or you can do something like:

Dim KillFilePath As String

KillFilePath = "c:\documents and settings\all users\desktop\easy*.xls"
If Len(Dir(KillFilePath)) > 0 Then
Kill KillFilePath
End If
 
Back
Top