Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-11-2018, 09:27 PM
gennylk gennylk is offline VBA Macro to Open password protected Word Documents Windows 8 VBA Macro to Open password protected Word Documents Office 2016
Novice
VBA Macro to Open password protected Word Documents
 
Join Date: Jan 2018
Posts: 2
gennylk is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 01-11-2018, 10:09 PM
gmayor's Avatar
gmayor gmayor is offline VBA Macro to Open password protected Word Documents Windows 10 VBA Macro to Open password protected Word Documents Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
If the correct password is in the list the document will be opened and the password for the document is the last one listed in the immediate window of the VBA editor (Ctrl+G),
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 01-11-2018, 11:03 PM
gennylk gennylk is offline VBA Macro to Open password protected Word Documents Windows 8 VBA Macro to Open password protected Word Documents Office 2016
Novice
VBA Macro to Open password protected Word Documents
 
Join Date: Jan 2018
Posts: 2
gennylk is on a distinguished road
Default

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.
Reply With Quote
Reply



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
VBA Macro to Open password protected Word Documents 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
VBA Macro to Open password protected Word Documents 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft