Thread: [Solved] Removing password protection
View Single Post
 
Old 02-04-2012, 12:37 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,344
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi HantsDave,

Try:
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)
  If wdDoc.ProtectionType <> wdNoProtection Then wdDoc.Unprotect
  wdDoc.Close SaveChanges:=True
  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
Simply input the password, select the folder and let it rip. Once the processing has finished, all documents in the folder should be unprotected.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote