Shauna
Sun Jan 13 02:56:30 PST 2008
Hi Scott
Just to be sure we're on the same track, I am assuming you are asking
about the password required to *open* a document (set at Tools > Options
> Security), not the password required to edit a document that has been
protected (set at Tools > Protect Document).
As far as I know, there is no way to ascertain whether a document
requires a password to open it.
However, Microsoft provides a useful file dsofile.dll at
http://support.microsoft.com/kb/224351. It lets you read document
properties of a Word document from outside Word. I don't know whether it
can tell you whether a document needs a password to open the document,
but a bit of experimentation should determine whether it will meet your
needs.
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
<scottmallory@gmail.com> wrote in message
news:89255c7d-89d9-439b-9c74-8ed0d316f7fe@f47g2000hsd.googlegroups.com...
>I over explained it...
>
> I am looking for a method to determine
> IF the word doc HAS a password BEFORE I try to open it.
>
> I'm thinking something like
> pDoc = Word.Documents.File("C:\somefile.doc")
> res = pDoc.IsProtected()
>
> Is this even possible?
>
>
> We are trying to keep word in the background as much as possible
> We're processing several hundred files, containing 100's of pages
>
> Scott
>
>
>
> On Jan 11, 8:03 pm, "Shauna Kelly"
> <ShaunaKe...@SendNoSpamToShaunaKelly.com> wrote:
>> Hi Scott
>>
>> I'm not sure that I really understand what you're trying to do, but
>> would the following help:
>>
>> Dim oDoc As Word.Document
>>
>> Set oDoc = Word.Documents.Open _
>> (FileName:="C:\wherever\whatever.doc", _
>> PasswordDocument:="PasswordToOpenThisDoc")
>>
>> There are, of course, risks associated with hard-coding a password.
>> If
>> your document holds the destruct sequence for a nuclear power station
>> this would not be a good way to do it. If your document is protected
>> to
>> prevent people from using the wrong version of the company logo, it
>> might not matter so much. Use your discretion.
>>
>> Hope this helps.
>>
>> Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
>>
>> <scottmall...@gmail.com> wrote in message
>>
>> news:cc2c2e30-2096-4f26-b9b6-7773b389b504@h11g2000prf.googlegroups.com...
>>
>> > Hello,
>> > I am trying to find a method via VBA or VB that will determine
>> > whether
>> > a MS Word Doc is password protected.
>> > A boolean result would be the best..
>>
>> > OR
>>
>> > can I trap for the Password Dialog that opens up when a passworded
>> > doc
>> > is opened and handle it myself via code?
>>
>> > Some Background
>> > We are trying to page out (each page as a seperate doc) a document
>> > that may or may not be passworded, a a background function of an
>> > application.
>>
>> > What we want to do it manage the password dialog event ourselves so
>> > we
>> > can keep word hidden away, and pass in the passwords in our open
>> > call
>> > as needed.
>>
>> > FYI: Word stays open when a password is required and looks like
>> > crap
>> > while we process 20 or more pages.
>>
>> > Thanks
>> > Scott
>