Link to home
Start Free TrialLog in
Avatar of Jack006
Jack006

asked on

Word OLE Automation VB6 - Bypassing Password on Document?

Hi.

I have written some code to loop through a folder, open relevant word docs, search the documents and add findings to a list box, then close then doc and so on. I am having a problem with documents that require a password or have advanced read only passwords etc which I do not have!

How am I able to bypass files that have those attributes and not attempt to open them? In other words, I do not want vb/word to attempt to open them if these factors are met?

Using the following without any parameters:

Set Doc = WordApp.Documents.Open(NewFileName)

Thanks
Jack
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Try it with any old password

Private Sub Command3_Click()
Dim wdapp As Word.Application
Dim doc As Word.Document
Set wdapp = New Word.Application
On Error GoTo ErrorProc:
Set doc = wdapp.Documents.Open("C:\CRO-1837Online.doc", , , , "WrongPassword")
MsgBox "Doc Opened"
Exit Sub
ErrorProc:
MsgBox "Doc has password"
End Sub
Avatar of Jack006
Jack006

ASKER


That's a great way of doing it - Nice one.
Just tested it and it works a lote better than it did before, however, i would like to bypass the file now (which in theory it does with the msgbox) and move onto the next file in the folder. I have substituted the Msgbox with a resume next, but now its popping up with the "Enter Password Screen" etc?

Any thoughts to skip to the next file and ignore the other?
Cheers
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jack006

ASKER


Possibly. Will test that now. Thanks and will get back to you soon .....
Avatar of Jack006

ASKER


Graham.

I have just had another look and it does the same with your code. In other words, the "Enter password" box becomes visible. I never had my app visible so that has really helped me understand why it halts (hangs up) - its because it waiting for a user input i.e. password or hit the cancel or hit the read-only buttom !! I dont understand why it just wont close the document and move on?

By the way, I am looping through a list box testing now, so I have substituted your array with the folowing:

For f = 0 To List1.ListCount
    List1.Selected(f) = True
    NewFileName = List1.Text
    Set doc = wdapp.Documents.Open(NewFileName, , , , "WrongPassword")

Thanks for your help.

Jack
I never see the "Enter password box", so I'm a bit puzzled.