- '批量删除EXCEL文件里的程序部分
- '引用:Microsoft Visual Basic for Applications Extensibility 5.3
- '宏安全性里勾选"信任对于"Visual Basic项目"的访问(V)"
- Private Sub CommandButton1_Click()
- On Error Resume Next
- Set fso = CreateObject("Scripting.FileSystemObject")
- fname = ActiveWorkbook.Path & "/xls"
- Set fd = fso.getfolder(fname)
- Set fls = fd.Files
- For Each fl In fls
- Set wb = Workbooks.Open(fname & "/" & fl.Name)
- With Application.VBE.ActiveVBProject
- For i = .VBComponents.Count To 1 Step -1
- LCount = .VBComponents(i).CodeModule.CountOfLines
- .VBComponents(i).CodeModule.DeleteLines 1, LCount
- .VBComponents.Remove .VBComponents(i)
- Next i
- End With
- wb.Save
- wb.Close
- Next
- MsgBox "DONE!"
- End Sub
VBA EXCEL中删除存在的宏
最新推荐文章于 2024-07-05 08:53:58 发布