Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Find if password set (WinNT/Word97)

    I need to run a macro on all files, skipping those that are passworded, but no matter what I try any code designed to find out if there is a password set just comes up 'invalid use of property' at debug. I think it's because asking it to check if the password is not nothing (<> "") involves it being able to see what the password is, and without said password it can't do that, but knowing why isn't helping me find out how to get past it! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    Please would someone tell me what I'm supposed to ask it to check to find out if there is a password!

    Many thanks in advance!
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find if password set (WinNT/Word97)


  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Find if password set (WinNT/Word97)

    Thanks, Hans - that should do it! I need to incorporate it into an existing routine rather than set it up and then do something ... if you see what I mean ... ?! ... but I'm sure I'll work it out! <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>

    Ta ever so muchly.
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find if password set (WinNT/Word97)

    Beryl,

    Here is a function you might be able to use.

    TryOpen takes the full path+filename of a document and returns a Document object if it succeeded, Nothing if it failed.

    Function TryOpen(strFileName As String) As Document
    On Error Resume Next
    Set TryOpen = Documents.Open( _
    FileName:=strFileName, _
    PasswordDocument:="?#nonsense@$")
    End Function

    Instead of code like

    Set oDoc = Documents.Open("F:WordBeryl.doc")
    ...
    oDoc.Close

    use

    Set oDoc = TryOpen("F:WordBeryl.doc")
    If Not oDoc Is Nothing Then
    ...
    oDoc.Close
    End If

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Find if password set (WinNT/Word97)

    Hans, you're a marvel! That should do it!

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Beryl M


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •