If you copy and paste the macro from the message into into the vba editor,
the macro when run prompts for the open and edit passwords. You don't have
to edit the macro code. The passwords you enter are assigned to the
variables sPassword1 and sPassword2 and those passwords are used for all the
documents. I did not include error trapping for missing or different macros
which is why I said that it was intended to work with a set of files all
with the same macro. See
http://www.gmayor.com/installing_macro.htm which
explains how to use and depoloy macro listings
Public Sub UnPasswordAll()
Dim FirstLoop As Boolean
Dim strFileName As String
Dim sPassword1 As String
Dim sPassword2 As String
Dim strPath As String
Dim oDoc As Document
Dim Response As Long
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "Password"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
sPassword1 = InputBox("Enter Password to open Document")
sPassword2 = InputBox("Enter Password to edit Document")
On Error Resume Next
Documents.Close SaveChanges:=wdPromptToSaveChanges
FirstLoop = True
strFileName = Dir$(strPath & "*.doc")
While strFileName <> ""
Set oDoc = Documents.Open(strPath & strFileName, _
PasswordDocument:=sPassword1, _
WritePasswordDocument:=sPassword2)
If FirstLoop Then
With ActiveDocument
.Password = ""
.WritePassword = ""
End With
FirstLoop = False
Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub
Else
With ActiveDocument
.Password = ""
.WritePassword = ""
End With
End If
oDoc.Close SaveChanges:=wdSaveChanges
strFileName = Dir$()
Wend
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>