如下代码为实现删除当前excel vba全部内容的宏命令,
如下代码为实现删除当前excelvba全部内容的宏命令,但是如果excel有密码,就不能删除,请问如果知道当前VBA工程密码为:123,如何增加代码,使得在带密码的exc...
如下代码为实现删除当前excel vba全部内容的宏命令,但是如果excel有密码,就不能删除,请问如果知道当前VBA工程密码为:123,如何增加代码,使得在带密码的excel文档里也可以实现删除宏命令代码。谢谢!
On Error Resume Next
Dim xlsApp As New Excel.Application
Dim xlsWorkBook As Excel.Workbook
Dim vbPro
Set xlsWorkBook = xlsApp.Workbooks.Open(sFileName)
Set vbPro = ActiveWorkbook.VBProject
With vbPro
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
xlsWorkBook.Save
xlsWorkBook.Close
xlsApp.Quit
补充一下,是去除vba工程保护的密码,不是去除工作表sheet的保护密码 展开
On Error Resume Next
Dim xlsApp As New Excel.Application
Dim xlsWorkBook As Excel.Workbook
Dim vbPro
Set xlsWorkBook = xlsApp.Workbooks.Open(sFileName)
Set vbPro = ActiveWorkbook.VBProject
With vbPro
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
xlsWorkBook.Save
xlsWorkBook.Close
xlsApp.Quit
补充一下,是去除vba工程保护的密码,不是去除工作表sheet的保护密码 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询