|
本帖最后由 usoler 于 2016-10-26 17:06 编辑
有上W份的WORD文档,但这些文档中都设置了编辑保护口令,通过网上找的一些工具只能一个文件一个文件地解除,请问哪位大神有批量处理的方法或工具?非常感谢。
比如:我的文件所在的路径为:C:\Users\usoler\Desktop\测试 (里面还有子目录)
编辑限制口令为:1111
我根据网上的说明:
打开一个WORD,ALT+F11,打开VB编辑器,增加模块,填写如下信息(比如我在附件中的 3.doc文件里添加后保存):
Option Explicit
Sub UnProtectAllDocFiles()
On Error Resume Next
Const strRootPath = "C:\Users\usoler\Desktop\测试\" ' 存放所有文件的目录,可以有子目录
Dim fso, oFolder
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(strRootPath)
UnProtectDocFilesUnderFolder oFolder
MsgBox "完成!"
End Sub
Sub UnProtectDocFilesUnderFolder(oFolder)
On Error Resume Next
Dim oSubFolder, oFile
Dim oDoc As Document
Const strPassword = "1111" ' 统一的密码
For Each oSubFolder In oFolder.SubFolders
UnProtectDocFilesUnderFolder oSubFolder
For Each oFile In oSubFolder.Files
Set oDoc = Documents.Open(FileName:=oFile.Path)
oDoc.Unprotect strPassword
oDoc.Close True
Next
Next
End Sub
保存后,点击F5进行执行,系统提示我“完成”,但是对WORD文档进行查看时,编辑限制保护口令还是存在。
解决后的方法一的代码(部分)(具体查看第12楼):Private Sub CommandButton1_Click()
Dim Jm As New Bej, pa$, pt$, fi$
Dim arr$(), n%, oDoc As Document
Const Pas = "1111": fi = "*.doc*"
Application.ScreenUpdating = False
Application.DisplayAlerts = wdAlertsNone
pa = ThisDocument.Path & "\"
pt = ThisDocument.FullName
arr = Jm.wwj(pa, pt, fi)
On Error Resume Next
Do While arr(n + 1, 1) <> ""
n = n + 1
Set oDoc = GetObject(arr(n, 1))
oDoc.Unprotect Pas
oDoc.Close -1
Loop
Application.DisplayAlerts = wdAlertsAll
Application.ScreenUpdating = True
MsgBox "解密完成!"
End Sub
解决后方法二的代码(具体查看第10楼):
Option Explicit
Sub UnProtectAllDocFiles()
Dim oSubFolder, oFile, oDoc
On Error Resume Next
Const strRootPath = "C:\Users\usoler\Desktop\测试"
Const strPassword = "1111"
Dim msg, fso, oFolder
msg = MsgBox("是否处理子目录下文档?", vbYesNo, "选择按钮。。。")
Debug.Print msg
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(strRootPath)
For Each oFile In oFolder.Files
Set oDoc = Documents.Open(FileName:=oFile.Path)
oDoc.Unprotect strPassword
oDoc.Close True
Next
If msg = 6 Then
UnProtectDocFilesUnderFolder oFolder, strPassword
End If
MsgBox "完成!"
End Sub
Sub UnProtectDocFilesUnderFolder(oFolder, strPassword)
On Error Resume Next
Dim oSubFolder, oFile
Dim oDoc As Document
For Each oSubFolder In oFolder.SubFolders
For Each oFile In oSubFolder.Files
Set oDoc = Documents.Open(FileName:=oFile.Path)
oDoc.Unprotect strPassword
oDoc.Close True
Next
Next
End Sub
|
|