Skip to content

Instantly share code, notes, and snippets.

@amorist
Created June 28, 2018 14:01
Show Gist options
  • Save amorist/09abb3f5e8a18fb9e53bf34b3bb77e7a to your computer and use it in GitHub Desktop.
Save amorist/09abb3f5e8a18fb9e53bf34b3bb77e7a to your computer and use it in GitHub Desktop.
Option Explicit
Sub UnProtectAllDocFiles()
On Error Resume Next
Const strRootPath = "F:\doc" ' 存放文档的目录
Const strPassword = "0216" ' 密码
Dim oDoc As Document
Dim fso, oFolder, oFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(strRootPath)
For Each oFile In oFolder.Files
Set oDoc = Documents.Open(FileName:=oFile.Path, PasswordDocument:=strPassword)
oDoc.Saved = False
oDoc.SaveAs FileName:=oFile.Path, Password:="", WritePassword:=""
oDoc.Close
Next
MsgBox "完成!"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment