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),