【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《根据excel表格删除指定文件夹文件》,欢迎阅读!
Private Function DelFS(FileName) As String
Dim FS, F
On Error Resume Next
If FileName = "" Then End
DelFS = "错误"
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile(FileName)
If Err > 0 Then
Beep
MsgBox ("删除指定的文件[" & FileName & "]出现错误。")
Else
F.Delete
DelFS = "已删除"
End If
End Function
Sub AutoDel()
Dim FDN, FN, FExt, Area
Dim Rng As Range
FDN = InputBox("输入文件所在文件夹名称:如C:\TEMP")
FExt = InputBox("输入文件的后缀名:如.jpg")
Area = InputBox("输入文件名所在表格范围:例如:A1:A50")
If FDN = "" Or Area = "" Or FExt = "" Then End
If MsgBox("点确认开始删除文件!") = vbCancel Then End
For Each Rng In Range(Area)
With Rng
If .Value <> "" Then
FN = FDN & "\" & .Value & FExt
.Offset(0, 1).Value = DelFS(FN)
End If
End With
Next
End Sub