skipping documents with a password

R

Rob

hi,

I need to do something with a lot of documents so i wrote
a routine which opens document after document (through
documents.open method) and correct the problem. Everything
went well until the routine opened a document which is
protected by a password. Then a dialog screen appears to
fill in the password. We want to run the macro overnight
and want to skip these documents but i cannot find any
code or possibility to do this....

does anyone have a suggestion?

Rob
 
H

Harold Kless

Try something like this:
Function OpenDocument(ByRef objWord As Object, ByVal sDoc As String) As
Boolean
'Arguments:
' objWord - a valid Word Application object.
' sDoc - the complete path and file name of the document to open in Word.
'
'Opens the document specified by the sDoc variable.
'This function returns True if the document is opened and is read-write.
'Else, this function returns False if the document cannot be opened,
'or if the document is opened read-only due to the "read-only recommended"
setting in the document.
'Therefore only if this function returns True should you attempt to modify
the document.
'If False is returned, log the sDoc into a text file and alert the user
'of the list of file(s) that could not be processed by the batch routine.
On Error GoTo EH
Dim oDoc As Object
Set oDoc = objWord.Documents.Open( _
FileName:=sDoc, _
ReadOnly:=False, _
PasswordDocument:="?#nonsense@$", _
WritePasswordDocument:="?#nonsense@$")
If oDoc.ReadOnly = True Then
OpenDocument = False
Else
OpenDocument = True
End If
CleanUp:
On Error Resume Next
Set oDoc = Nothing
Exit Function
EH:
'There was an error opening the file. Return False
OpenDocument = False
Resume CleanUp
End Function
Hope that this helps,

--
Harold Kless, MCSD
Support Professional
Microsoft Technical Support for Business Applications
(e-mail address removed)

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
 

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