delete a file macro

J

jnu

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
 
S

Steve Schapel

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.
 
J

jnu

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
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top