|
各位老师好,在同一文件夹下面有很多个工作簿,每个工作簿的打开密码还不一定一样,我需要通过遍寻该文件夹下的工作簿,然后删除工作簿里面多个表格所隐藏的对象(使用ctrl+G的方式删除太慢了,表格很多),然后保存工作簿的时候,把工作簿的打开密码去掉。我是个VBA菜鸟,我搜索了很多老师的成果,然后拼凑了一个代码,好像不起作用,而且一运行就卡死!打开工作簿的密码有四个,如下表格:
Sub 批量删除对象()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sr$, wb As Workbook, ws As Worksheet, ps As String
Dim vData As Variant, nRow As Integer
Dim sPassword As String
sr = Dir(ThisWorkbook.Path & "\*.xls")
vData = Sheet1.UsedRange.Value
Do
'For nRow = 2 To UBound(vData)
'sr = Dir(ThisWorkbook.Path & "\*.xls")
'If sr <> "" Then
'sPassword = IIf(Trim(vData(nRow, 2)) = "无", "", Trim(vData(nRow, 2)))
Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & sr)
With ActiveWorkbook
b = ActiveWorkbook.Sheets.Count
For I = 1 To b
Worksheets(I).DrawingObjects.Delete
Next I
sr = Dir
.SaveAs Password:="" '删除文件保护密码
.Close True
End With
'End If
Loop Until sr = ""
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
|
|