要从文件夹里面删除文件的话,可以使用下面的Kill语句:
Kill 文件路径名
文件路径名明确一个或多个你要删除的文件的名称,随你意,也可以将驱动器和文件夹名称包括在里面。你可以在文件路径名参数里使用通配符(*或?)来确保快速删除文件。你不能删除开启的文件。
Sub RemoveMe()
Dim folder As String
Dim myFile As String
'assign the name of folder to the folder variable
'notice the ending backslash "\"
folder = "D:\try\"
myFile = Dir(folder, vbNormal)
Do While myFile <> ""
Kill folder & myFile
'delete the file objects first and then delete
myFile = Dir
Loop
RmDir folder
End Sub
运行,发现相应的文件夹及其里面内容已经消失。