|
楼主 |
发表于 2024-8-6 09:41
|
显示全部楼层
问题已经解决,感谢社区的大神,分享代码给大家
- Sub ykcbf() '//2024.8.5 工作簿加密
- Dim fn, wb
- Application.DisplayAlerts = False
- Application.ScreenUpdating = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & ""
- r = Cells(Rows.Count, 1).End(3).Row
- For i = 2 To r
- s = Cells(i, 1)
- If s <> Empty Then d(s) = Array(Cells(i, 2), Cells(i, 3))
- Next
- For Each f In fso.GetFolder(p).Files
- If LCase$(f.Name) Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- fx = fso.GetExtensionName(f)
- If InStr(fx, "xlsx") Then mm = 51 Else mm = 56
- If d.exists(fn) Then
- PW = d(fn)(0)
- RW = d(fn)(1)
- With Workbooks.Open(f)
- .SaveAs Filename:=f, FileFormat:=mm, Password:=PW, WriteResPassword:=RW
- .Close
- End With
- End If
- End If
- End If
- Next f
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- MsgBox "处理完毕!"
- End Sub
复制代码
|
|