Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Jul 2002
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Doc (XP) Need some help with VB code (Word 2002 (XP))

    I brought this up before but am unable to figure out the code.

    I have a document template with two sections. When the template is opened by the user, it is protected. The second section, however, is not protected, but the document as a whole is. I need to know how to write code so that when the user enters the second section of the doc (or leaves the first section), the document becomes unprotected. Whenever the user enters the first section, the document then becomes protected again (without losing any of the entered data in the form)

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Word Doc (XP) Need some help with VB code (Word 2002 (XP))

    I don't think you actually need code for this.

    You can protect the first section 'For Forms' whilst leaving the second section unprotected. This is done by choosing Tools > Protect Document. Now select the forms option and click the Sections button.

    If you protect the first section but not the second then the behaviour you describe will be present without needing code to perform tests fly everytime you move your insertion point which would be a huge processing overhead.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    Jul 2002
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not actually true...

    Even though the second section is unprotected, it loses functionality. You are unable to do things such as insert autoshapes, or textboxes, or format a picture. These function will become available once I unprotect the entire document. This is why I need to get code to unprotect the entire document when i enter section 2, and protect the document whenever i leave section two (enter section 1).

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Not actually true...

    Ah hah. Now I remember the previous thread. Sorry, I have a bad memory, and I'll tell you another thing - I don't remember much either

    I don't know of a way to run a macro which will fire every x seconds in Word. Even if you could do it, it would slow down your general use of the software. I also know of no document event which fires when the cursor or mouse moves across a section break.

    The only way I can imagine this could occur is to use the on exit event for all the form fields to test the position of the cursor and if >Section1 then unlock the document. This would assume that section 1 is aleady locked.

    Now coming back up a section is a little trickier. User Forms have plenty of events but the Word document itself doesn't have too many. Does the OnTimer event show any promise if you can make it loop continuously? I would expect that while it is running, you won't get any other macros to run. Is that a problem?

    I suppose a button on the toolbar to unprotect the document is too much work. 8-) I think you should shrug off the obvious limitations here and add a menu item or toolbar button which will reprotect the first section for you when you need to.

    How many users need to use this template? How often? Can they be trained?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger
    Join Date
    Jul 2002
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Not actually true...

    Interesting point you bring up... the toolbar icon. I tried to design this form for the least common denominator... the idiot who just can seem to learn beyond a couple of steps. If the forms toolbar were displayed, a simple click of the lock/unlock icon does the trick. However, to tell people to make sure this toolbar was present would probably work for only half of the users. But.... I never though of a macro that makes the form lock/unlock icon always appear above. Is this possible and/or easy to do????

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Not actually true...

    Try
    Sub AutoOpen()
    CommandBars("Forms").Visible = True
    End Sub

    You will also need code to stop the form fields from being emptied automatically (unless you are using Word XP). That code has been posted here previously.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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