It appears the code I provided would only remove forms protection, not the open/write protection. Try the following instead:
Code:
Sub UnprotectDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strPwd As String, strFile As String, wdDoc As Document
strPwd = InputBox("What is the password?", "File Password")
If strPwd = "" Then Exit Sub
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, _
Visible:=False, PasswordDocument:=strPwd, WritePasswordDocument:=strPwd)
With wdDoc
'.ReadOnlyRecommended = False
.Password = vbNullString
.WritePassword = vbNullString
.Close SaveChanges:=True
End With
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
As for the error message, what kind of document & module did you add the code to? If it was added to an ordinary document, I wouldn't expect such a message unless there was some kind of dialogue box open.