Solved

Word OLE Automation VB6 - Bypassing Password on Document?

Posted on 2004-09-13
6
232 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:Jack006
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12043198
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
0
 

Author Comment

by:Jack006
ID: 12043417

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
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 12043579
I can't be sure,but I think you might have a logic error somewhere.
I can run this OK. There is a password on the first doc and none on the second.
The second is open when I get the '"Open" message

Private Sub Command3_Click()
Dim wdapp As Word.Application
Dim doc As Word.Document
Dim Files
Dim f As Integer
On Error GoTo ErrorProc:
Set wdapp = New Word.Application
wdapp.Visible = True
For f = 0 To 1
    Files = Array("C:\CRO-1837Online.doc", "c:\logo.doc")
    Set doc = wdapp.Documents.Open(Files(f), , , , "WrongPassword")
    MsgBox "Doc Opened"
    doc.Close
NextDoc:
Next f
wdapp.Quit
Exit Sub
ErrorProc:
Resume NextDoc
End Sub


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Jack006
ID: 12043623

Possibly. Will test that now. Thanks and will get back to you soon .....
0
 

Author Comment

by:Jack006
ID: 12043804

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
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12044196
I never see the "Enter password box", so I'm a bit puzzled.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question