|
楼主 |
发表于 2019-7-24 11:13
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 f8b1987 于 2019-7-29 12:53 编辑
- Sub 删除模块等()
- '------------------单个文件夹,不含子文件夹
- Dim VBP As Object, vbc As Object, shp As Shape, sh As Worksheet
- On Error Resume Next
- Application.ScreenUpdating = False '冻结屏幕,以防屏幕抖动
- Application.AskToUpdateLinks = False '不更新链接
- Application.DisplayAlerts = False '不提示窗口
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show Then
- Path = .SelectedItems(1)
- File = Dir(Path & "\*.xls*")
- Application.EnableEvents = False
- Application.Calculation = xlCalculationManual
- Do Until LenB(File) = 0
- Set Wb = Workbooks.Open(Filename:=Path & "" & File)
- ' For Each sht In Wb.Sheets
- ' If sht.Type = xlExcel4MacroSheet Or sht.Name Like "Macro*" Then '判断是否宏表4.0
- ' sht.Visible = True
- ' sht.Delete
- ' End If
- ' Next sht
- For Each m In Wb.VBProject.VBComponents
- If m.Name Like "*" Then
- m.CodeModule.DeleteLines 1, m.CodeModule.CountOfLines
- Wb.VBProject.VBComponents.Remove m
- End If
- ' '===========================以下一段指定删除窗体、模块、类模块、Excel对象
- ' If m.Type = 3 Then ''模块的值为1,类模块为2,窗体type值为3,Sheet及Thisworkbook为100
- ' m.CodeModule.DeleteLines 1, m.CodeModule.CountOfLines
- ' Wb.VBProject.VBComponents.Remove m
- ' End If
- ' '============================================
- Next m
- Wb.Close savechanges:=True '关闭
- File = Dir
- Loop
- End If
- End With
- Application.ScreenUpdating = True '恢复屏幕刷新
- Application.AskToUpdateLinks = True '更新链接
- Application.DisplayAlerts = True '提示窗口
- Application.Calculation = xlCalculationAutomatic '恢复自动重算
复制代码
方便大家针对性删除窗体、模块、类模块等,重新添加代码判断对象类型,判断部分已注释,请自行解除注释。
|
|