Excel VBA 删除指定文件夹中的指定文件

比如我D:\报表\ 中有几个文件(如:中国什么省汇总.xls)
用VBA怎么做!!!!

'你想删除的文件的名称例如文件名是中国什么省汇总.xls
FN = "中国什么省汇总.xls"

Dim FileName As String

FileName = Dir("D:\报表\*.xls")
Do While FileName <> ""
If FileName = FN Then
Kill "D:\报表\" & FileName
End If
FileName = Dir
Loop
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-01-23

试试!

Sub test()
    Dim FileName As String
    FileName = Dir("D:\报表\*.xls*")
    Do While FileName <> ""
        Kill "D:\1\" & FileName
        FileName = Dir
    Loop
End Sub

第2个回答  2014-01-23
用DeleteFile 方法,你参考这个吧
http://www.officefans.net/cdb/viewthread.php?tid=70143
试试吧,有问题再讨论,祝你成功!