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
Solved

Word OLE Automation VB6 - Bypassing Password on Document?

Posted on 2004-09-13
6
212 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 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to add contact name to VBA code to automate emails in outlook using a Template 11 89
Determine Range to Select 5 52
TT Auto Dashboard 13 95
Problem to line 23 54
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 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