2017-10-17 12 views
0

複数の文書があり、開発者モードからの制限が必要です。VBAを使用してフォルダ内の複数ワード文書の保護を解除する

私はそれはあなたが同じようにファイルを保護するために同様のコードを使用することができます

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 
+0

どのようなエラーが投げられ、どの行にありますか? –

+0

https://stackoverflow.com/questions/42194300/does-vbscript-allow-named-arguments-in-function-calls –

+0

エラーのテキストは何ですか? –

答えて

1
Sub UnprotectDocsInFolder() 
Dim docfile As Document 
Dim docpath As String 
Dim docfilename As String 
Dim pwd As String 

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

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

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

エラー苦しみ引数としてフォルダを渡すのWScriptを使用してスクリプトを実行し、しかし。

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 
関連する問題