|
我有一个.xls的表另存到D盘下,如何设置代码另存的时候把D盘下的该文件代码删了?
从网上看来的代码,弄到我的表里就在with workbooks.open(s)这一段过不去了,提示1402错误
Dim vbc As Object, shp As Shape, s$, sh As Worksheet
s = ThisWorkbook.Path & "\备份" & ThisWorkbook.Name
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ThisWorkbook.SaveCopyAs s
With Workbooks.Open(s)
For Each sh In .Sheets
For Each shp In sh.Shapes
shp.Delete
Next
Next
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
.Close True
End With
|
|