Good morning!
Using code from this forum (Macropod's), I am trying to remove (open) passwords from all files within a folder. All files share the same password. I'd like to remove the password and resave the files. Ideally, I'd like to re-save them in a new folder; however, I would be ecstatic if I can get them to save without password.
I've spent several hours over a couple of days trying to figure this out on my own, but I have been unsuccessful. Following is my latest failed attempt.
Thank you in advance for reviewing the code, and I appreciate any suggestions.
Code:
Sub DeleteAllOpenPW()
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
Dim StrPassword As String
Application.ScreenUpdating = False
strDocNm = ActiveDocument.FullName: strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.docx", vbNormal)
StrPassword = InputBox("What is the password to delete?", "Password")
While strFile <> ""
If strFolder & "\" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(Filename:=strFolder & "\" & strFile, PasswordDocument:=StrPassword, AddToRecentFiles:=False, Visible:=False)
With wdDoc
wdDoc.SaveAs strFolder & strFile, Password:=""
.Close SaveChanges:=True
End With
End If
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