Solved

Word OLE Automation VB6 - Bypassing Password on Document?

Posted on 2004-09-13
6
203 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA to format 3 80
Controlling which port to download from 4 62
Reading the Contents of a Directory In Access VBA 5 47
MsgBox 2 37
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now