使用VBA取消保护文件夹中的多个word文档

使用VBA取消保护文件夹中的多个word文档,vba,ms-word,wsh,Vba,Ms Word,Wsh,我有多个word文档,需要开发者模式对它们施加限制 我使用wscript运行脚本,并将文件夹作为参数传递,但它遇到了一个错误 Dim strFolder Const xlTypePDF = 0 strFolder = WScript.Arguments(0) if Wscript.Arguments.Count > 0 Then Set objFSO = CreateObject("Scripting.FileSystemObject") Set objWord =

我有多个word文档,需要开发者模式对它们施加限制

我使用wscript运行脚本,并将文件夹作为参数传递,但它遇到了一个错误

Dim strFolder
Const xlTypePDF = 0
strFolder = WScript.Arguments(0)

if  Wscript.Arguments.Count > 0 Then

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objWord = CreateObject("Word.Application")
    Set objFolder = objFSO.GetFolder(strFolder)

    For Each Fil In objFolder.Files
        Set objFile = objFSO.GetFile(Fil)

        Set objDoc = objWord.Documents.Open(Fil,,TRUE)
        dirPath = objFSO.GetParentFolderName(objFile)
        fileBaseName = objFSO.GetBaseName(objFile)

'objWord.ActiveDocument.Unprotect Password:="pwd" 

        objWord.ActiveDocument.Close(False)
    Next

    objWord.Quit
Else
    Msgbox("Run usning cmd")
End If
您可以使用类似的代码以相同的方式保护文件

Sub ProtectDocsInFolder()
Dim docfile As Document
Dim docpath As String
Dim docfilename As String
Dim pwd As String

    'Path for the documents
    docpath = "C:\UnProtectedDocs\"
    'Password
    pwd = "myPass"

    docfilename = Dir(docpath & "*.doc")

    Do Until docfilename = ""
        Set docfile = Documents.Open(docpath & docfilename)
        docfile.Protect wdAllowOnlyFormFields, , pwd
        docfile.Close True
        docfilename = Dir()
    Loop
End Sub

它会抛出什么错误,在哪一行?错误的文本是什么?
Fil
只会给出文件名,而不是完整路径。。尝试设置objDoc=objWord.Documents.Open(objFSO..BuildPath(strFolder,Fil),TRUE)
Sub ProtectDocsInFolder()
Dim docfile As Document
Dim docpath As String
Dim docfilename As String
Dim pwd As String

    'Path for the documents
    docpath = "C:\UnProtectedDocs\"
    'Password
    pwd = "myPass"

    docfilename = Dir(docpath & "*.doc")

    Do Until docfilename = ""
        Set docfile = Documents.Open(docpath & docfilename)
        docfile.Protect wdAllowOnlyFormFields, , pwd
        docfile.Close True
        docfilename = Dir()
    Loop
End Sub