|
yzyyyyyyy 发表于 2014-5-22 18:30
假定都没有VBA密码
代码放在模块里,试试:
Sub 删除代码1()
Dim Wb As Workbook, vbc As VBComponent, fname, i%
Application.DisplayAlerts = False: Application.ScreenUpdating = False: Application.EnableEvents = False
fname = Application.GetOpenFilename(filefilter:="Excel 文件, *.xl*,所有文件, *.*", MultiSelect:=True)
If VarType(fname) = vbBoolean Then End
For i = 1 To UBound(fname)
If fname(i) <> ThisWorkbook.FullName Then
If Len(Dir(Left(fname(i), InStrRev(fname(i), ".")) & "bak")) = 0 Then
FileCopy fname(i), Left(fname(i), InStrRev(fname(i), ".")) & "bak"
End If
Set Wb = Workbooks.Open(fname(i))
With Wb
For Each vbc In .VBProject.VBComponents
Select Case vbc.Type
Case 1, 2, 3
With Application.VBE.ActiveVBProject.VBComponents
.Remove .Item(vbc.Name) '删除模块、类模块、窗体
End With
Case Else
vbc.CodeModule.DeleteLines 1, vbc.CodeModule.CountOfLines '删除工作表或Thisworkbook代码区代码
End Select
Next
.Save
.Close False
End With
Set Wb = Nothing
Set vbc = Nothing
End If
Next i
Application.DisplayAlerts = True: Application.ScreenUpdating = True: Application.EnableEvents = True
End Sub
....
|
|