|
发表于 2012-4-22 19:55
|
显示全部楼层
本楼为最佳答案
- Sub test()
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- Application.DisplayAlerts = False
- On Error Resume Next
- Set Myf = CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件目录:", &H1)
- If Not Myf Is Nothing Then
- Directory = Myf.self.Path
- End If
- MyName = Dir(Directory & "\*.xls")
- Do While MyName <> ""
- Workbooks.Open (Directory & "" & MyName)
- With ActiveWorkbook
- '***********删除工作表和宏
- .Sheets("Sheet1").Delete '删除工作表
- '**删除各模块内容
- With .VBProject.VBComponents("ThisWorkbook").CodeModule
- .DeleteLines 1, .CountOfLines
- End With
- With .VBProject.VBComponents("模块1").CodeModule
- .DeleteLines 1, .CountOfLines
- End With
- With .VBProject.VBComponents("UserForm1").CodeModule
- .DeleteLines 1, .CountOfLines
- End With
- With .VBProject.VBComponents("sheet1").CodeModule
- .DeleteLines 1, .CountOfLines
- End With
- '**删除模块
- .VBProject.VBComponents.Remove .VBProject.VBComponents("模块1")
- '*****************
- .Close True
- End With
- MyName = Dir
- Loop
- Application.EnableEvents = True
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|