1、首先新建一个excel文件并双击打开,打开后,按快捷键F12进行另存为,注意另存的格式要选择启用宏的工作簿,
2、接着找到左上角的文件按钮,选择选项按钮,
3、在弹出的对话框中选择信任中心,并选择信任中心设置,接着选择隐私选项,并把保存时删除个人信息的对号去掉,整体设置完成,按快捷键ALT+F11,打开VBA编辑界面,并插入一个模块
4、插入后将如下代码复制到模块中,Sub 删除指定文件夹下的所有文件()
For i% = 1 To Range("A1048576").End(xlUp).Row
Kill Cells(i, 1) & "\*.*”
Next
End Sub
1、复制如下代码执行即可。
3、
Dim arrf(), mf&
Sub VBA代码一次性删除同一个目录下的所有xls文件所有名称()
Dim Fso As Object, i&, sFileType$, na As Name
Application.ScreenUpdating = False
Set Fso = CreateObject("Scripting.FileSystemObject")
sFileType = "*.xls"
Call GetFiles(ThisWorkbook.Path, sFileType, Fso)
For j = 1 To mf
With Workbooks.Open(arrf(j))
For Each na In .Names '历遍打开的工作簿所有名称
na.Delete '删除名称
Next
.Close True '保存关闭
End With
Next
mf = 0
Erase arrf
Set Fso = Nothing
Application.ScreenUpdating = True
MsgBox "ok"
End Sub
Private Sub GetFiles(ByVal sPath$, ByVal sFileType$, Fso As Object)
Dim Folder As Object
Dim SubFolder As Object
Dim File As Object
Set Folder = Fso.GetFolder(sPath)
For Each File In Folder.Files
If File.Name Like sFileType Then
If File.Name <> ThisWorkbook.Name Then
mf = mf + 1
ReDim Preserve arrf(1 To mf)
arrf(mf) = sPath & "\" & File.Name
End If
End If
Next
If Folder.SubFolders.Count > 0 Then
For Each SubFolder In Folder.SubFolders
Call GetFiles(SubFolder.Path, sFileType, Fso)
Next
End If
Set Folder = Nothing
Set File = Nothing
Set SubFolder = Nothing
End Sub