Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Word OLE Automation VB6 - Bypassing Password on Document?

Posted on 2004-09-13
6
Medium Priority
?
245 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
  • 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 2000 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
Technology Partners: 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

885 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