![]() |
#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 |
Thread Tools | |
Display Modes | |
|
![]() |
||||
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 |
![]() |
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 |
![]() |
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 |