vba 删除文件夹下所有

Excel VBA中实现删除D:\Test\temp目录下的所有文件夹和文档
请给出具体代码

第1个回答  2014-10-15
Sub Test()
    Dim fs As Object
    Set fs = CreateObject("scripting.filesystemobject")
    fs.deletefile "D:\Test\temp\*.*"
    fs.deleteFolder "D:\Test\temp\*.*"
End Sub

第2个回答  2014-10-15
Sub mydel()
Shell "cmd.exe /c rd/s/q d:\test\temp\"
End Sub追问

只删除D:\Test\temp目录下的所有,temp文件夹要保留

追答

Sub mydel()
Shell "cmd.exe /c rd/s/q d:\test\temp\"
Shell "cmd.exe/c md d:\test\temp"
End Sub

追问

Shell "cmd.exe/c md d:\test\temp" ---> 运行时错误 '53' 文件未找到

追答

不好意思,少了一个空格
Sub mydel()
Shell "cmd.exe /c rd/s/q d:\test\temp\"
Shell "cmd.exe /c md d:\test\temp"
End Sub
你再试。

本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网