#1
|
|||
|
|||
VBA Macro to Open password protected Word Documents
Hi There,
I have a Word Document which is password protected. I think I may know the password, but it is one of around 20 possible passwords. I wanted to create a macro that has the list of passwords (probably in a static array) and want to try to open it one by one using a loop. When the file opens, Perhaps remove the password and save it or pop up the working password. Any assistance on how I can try to open another file from a different word document ? Thanks Genny |
#2
|
||||
|
||||
If you don't have the right password then you cannot open the document with VBA, however you can test it with a list of passwords e.g.
Code:
Sub Macro1() Const strPassword As String = "Test|password|Lorem|another" 'List the passwords separated with '|' Const strName As String = "E:\Path\Forum\Password is lorem test.docx" 'The document to open Dim oDoc As Document Dim vPass As Variant Dim i As Integer vPass = Split(strPassword, "|") On Error Resume Next For i = 0 To UBound(vPass) Debug.Print vPass(i) Set oDoc = Documents.Open(FileName:=strName, _ PasswordDocument:=vPass(i), _ ReadOnly:=True) If Not oDoc Is Nothing Then Exit For Next i lbl_Exit: Set oDoc = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thank you GMayor, this is exactly what i was looking for. I wasnt sure which password to use, so this should help, as I can put all my guess list in this. Thanks So much.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Password protected file no longer offers password dialog on Open | htaylor | Word | 0 | 10-15-2013 12:35 PM |
Cannot open emailed documents in Word 2010 - Protected View | Andrewjmarino | Word | 8 | 09-05-2013 03:58 PM |
How to open a password-protected word document? | navalava | Word | 1 | 07-01-2012 12:15 PM |
Mail merge and password protected documents | sheep_go_baa | Mail Merge | 1 | 01-17-2012 03:31 PM |
No Password Prompt on Protected Documents | tek4u | Word | 0 | 03-15-2011 10:02 AM |