password protect

G

greg

Hello,
I need to write a program to open and update a bunch of word documents.
problem is, that some are password protected.
and if i hit them, then the user password dialog opens.
is there a way to tell if a document is password protected? an open
command?
so i know to skip that document?

thanks
 
D

Dav

greg said:
Hello,
I need to write a program to open and update a bunch of word documents.
problem is, that some are password protected.
and if i hit them, then the user password dialog opens.
is there a way to tell if a document is password protected? an open
command?
so i know to skip that document?

thanks
Greg

You could possible try this code, obviously the below is only setup for
just one document, so you would need to amend it for multiple files. If
the document being opened doesn't have a password then the password
option is ignored.

Hope it helps.

Sub checkIfProtected()
Dim docName As String
Dim txtFile As String
On Error Resume Next
docName = "Test Protected document.doc"
Documents.Open FileName:=docName, _
PasswordDocument:="openDoc", _
WritePasswordDocument:="openDoc"
'The password doesn't need to be valid,
'just needs to generate an error

If Err.Number = 5408 Then
' Code assumes protected.txt already exists
' Builds a list of protected documents
txtFile = ThisDocument.Path & "\protected.txt"
Open txtFile For Append As #1
Write #1, "Password protected: > " & docName
Close #1
End If
' If Read-Only and no password
' If you're making amendments then you wont be able
' save with the same filename
If ActiveDocument.ReadOnly = True Then
txtFile = ThisDocument.Path & "\protected.txt"
Open txtFile For Append As #1
Write #1, "Read-Only: > " & docName
Close #1
End If
End Sub

Regards

Dav
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top