|
把下面代码放在个人宏文件中(Personal.xls)
运行宏以后可以打开别的文件并去除所有代码和模块。- Sub MacroDel_OtherFile()
- '引用 Microsoft Visual Basic For Application Extensibility 5.3
-
- With Workbooks.Open(Application.GetOpenFilename(",*.xls"))
- For Each vbc In .VBProject.VBComponents
- Select Case vbc.Type
- Case 1, 2, 3 'vbext_ct_StdModule/ClassModule/MSForm
- With Application.VBE.ActiveVBProject.VBComponents
- .Remove .Item(vbc.Name)
- End With
- Case Else '100=vbext_ct_Document (Sheet/ThisWorkbook)
- vbc.CodeModule.DeleteLines 1, vbc.CodeModule.CountOfLines
- End Select
- Next
- Application.DisplayAlerts = False
- .SaveAs .path & "\Backup" & Format(Date, "-yyyy-mm-dd") & ".xls"
- .Close False
- End With
- End Sub
复制代码 |
|