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

    Protect/Unprotect (WinXP, Wd2003)

    I is confuggulated!! Not unusual, of course, but ...! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Anyway, I have this mini-macro, which has been built into my startup template for several years and is run from a button on the toolbar:

    Sub ProtectUnprotect
    If ActiveDocument.ProtectionType = wdNoProtection Then ActiveDocument.Protect Password:="", _
    NoReset:=False, Type:=wdAllowOnlyFormFields _
    Else ActiveDocument.Unprotect
    End Sub

    Basically, if the doc's not protected it protects it, without a password; if it is, it unprotects it - and prompts you to fill the password in, if there is one. At least, that's what it did in Word 97.

    Now, in Word 2003, if the doc is already protected with a password, it just crashes out saying the wrong password has been entered! I've checked the Wd2003 help and it states quite clearly that "ActiveDocument.Unprotect" without the password qualifier should behave as it originally did - so why doesn't it?!

    <img src=/S/sad.gif border=0 alt=sad width=15 height=15> No fair!
    Beryl M


  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Protect/Unprotect (WinXP, Wd2003)

    Beryl try this

    Sub ToolsProtectUnprotectDocument()

    If ActiveDocument.ProtectionType = wdNoProtection Then
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
    NoReset:=True
    Else
    ActiveDocument.Unprotect Password:=""
    End If

    End Sub
    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17>It may have been because you inadvertently deleted the last End If <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Jerry

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

    Re: Protect/Unprotect (WinXP, Wd2003)

    Beryl has one statement broken into several lines by using the line continuation character _ instead of a multi-line If ... End If block.

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

    Re: Protect/Unprotect (WinXP, Wd2003)

    It's either a bug introduced in Word 2003, or Microsoft forgot to adjust the VBA help. You can work around it by replacing

    ActiveDocument.Unprotect

    with

    CommandBars.FindControl(ID:=7116).Execute

    This "runs" the Tools | Unprotect Document menu option, displaying the password prompt if needed.

  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: Protect/Unprotect (WinXP, Wd2003)

    Thanks, Hans - I would never have worked that one out! Also for defending my code/honour above!

    The silly thing is, in order to use this macro now I have had to convert it into a block if ... end if because I've had to add "CommandBars("Task Pane").Visible = False" on the end to get rid of the stupid task pane Word now brings up! I wonder how many other "quick" macros I'm going to have to add that line to now I'm using 2003?!

    <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15> Ain't progress wonderful?!
    Beryl M


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

    Re: Protect/Unprotect (WinXP, Wd2003)

    I initially hated the task pane when I switched to Word 2002, but I kind of like it now. It does make some things easily available, and on my 1280x1024 monitor it leaves enough room for the document.

  7. #7
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Protect/Unprotect (WinXP, Wd2003)

    Sorry Beryl, I didn't mean to criticise, I need new glasses <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>
    Jerry

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

    Re: Protect/Unprotect (WinXP, Wd2003)

    Don't be silly, Jerry! I'm famous for wording my queries so badly people continually mis-read what I said - just ask Hans! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Thanks for trying, anyway - looks like I actually found a new one of Microsoft's "undocumented features"!!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


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

    Re: Protect/Unprotect (WinXP, Wd2003)

    Well, I'm still at the hating it stage and I can't yet envisage any light at the end of that tunnel! Not helped by the fact that my work monitor is at 1024x768 so I don't have so much space here as you do (or I do at home)!

    Two steps forward, one step back ... or maybe it's the other way around ... <img src=/S/sigh.gif border=0 alt=sigh width=15 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
  •