Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    McLean, VA
    Posts
    125
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Reminder to Re-protect document upon closing heade (2000/SR1)

    The templates I'm designing for users to create standard reports employ form fields and document protection. The users are required to enter a control number in the header, and I've provided them with a toolbar button to unprotect the document to allow them access to the header. I'm concerned that they will forget to re-protect the document once they close the header. Is there a way to generate a popup message that reminds them to re-protect the document after they close the header? Or perhaps, instead of a reminder, a macro that automatically re-protects it for them?

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

    Re: Reminder to Re-protect document upon closing heade (2000/SR1)

    Instead of letting the users enter the control number in the header directly, you could have your toolbar button ask for this number, unprotect the document, put the control number in the appropriate place, and reprotect the document. The easiest way to ask for the control number is to use the InputBox function; if you want to be fancier, you could create a UserForm for this purpose.

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    McLean, VA
    Posts
    125
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Reminder to Re-protect document upon closing heade (2000/SR1)

    Thanks, Hans. The InputBox appears to be exactly what I need here, but I've never used one before. After reading the Special Edition Using Word 2000 blurb, I was able to create the InputBox, and I know (from using a MsgBox) that my variable (txtCtrlNum) is being assigned the string value the user gives. But now that I have this variable, I don't know how to get its contents into the header. I tried the DocVariable field, but it isn't getting populated with the contents of txtCtrlNum. How should my toolbar button be able to do all the things you say it should do?

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

    Re: Reminder to Re-protect document upon closing heade (2000/SR1)

    I would use a field in the header that displays a document property and use the macro to change the value of the document property and update the fields.
    The field could look like
    {DocProperty "Category"}

    and the code could be<pre>ActiveDocument.BuiltInDocumentProperties(wd PropertyCategory) = strValue
    'Updates the fields in entire document
    Dim rngStory As Word.Range
    For Each rngStory In ActiveDocument.StoryRanges
    rngStory.Fields.Update
    Next rngStory</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    McLean, VA
    Posts
    125
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Reminder to Re-protect document upon closing heade (2000/SR1)

    Thanks, Andrew. I'm not having success in completely implementing your solution. I was able to create a custom property called CTRLNumber and insert a DocProperty field into the header which displays the default value which I defined for CTRLNumber. But in trying to run your macro, I get an error in the first line. Also, it's not clear to me how your macro asks the user to provide a new value for the CTRLNumber property.
    If there was a way to link a custom property to a variable, maybe I could use a combination of your method and Hans's. I could link the CTRLNumber custom property to the content of the variable that results from the InputBox. But I see only bookmark names, and no variables, in the dropdown list in the custom property dialog box when I select the Link To Content checkbox.

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

    Re: Reminder to Re-protect document upon closing heade (2000/SR1)

    George,

    strValue should be the return value of the InputBox function:

    Dim strValue As String
    strValue = InputBox("Enter control number")
    If strValue <> "" Then
    ActiveDocument.BuiltInDocumentProperties(wdPropert yCategory) = strValue
    End If

    You don't need LinkToContent here - that works the other way round: if the text of a bookmark is updated, the document property linked to it is updated too. Here, you want a field in the document to display the value of the document property.

    In this example, one of the built-in document properties is used (after it has been set, you can view it in the Summary tab of File/Properties). Instead, you could use a custom property: first, define a custom property ControlNumber manually. Then, you can adapt the above code to work with the custom property instead of a built-in property:

    Dim strValue As String
    strValue = InputBox("Enter control number")
    If strValue <> "" Then
    ActiveDocument.CustomDocumentProperties("ControlNu mber") = strValue
    End If

    HTH

  7. #7
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    McLean, VA
    Posts
    125
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Reminder to Re-protect document upon closing heade (2000/SR1)

    Thanks again, Hans! It worked! I was able to get it to work for the control number, and then I added a second input box for the date, which also is required to be in the header. A great learning experience for me - I'm sure I'll use this technique for many other templates, and I do have a ton more of them to do.
    One more question if I might: The custom doc property dialog doesn't seem to recognize the "d mmm yyyy" format, so I had to define the field as Text. Any insight on this?

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

    Re: Reminder to Re-protect document upon closing heade (2000/SR1)

    You (and your users) must enter the date in a format that Windows can interpret as a valid date (in the user's regional settings).

    You can format the DocProperty field:
    <UL><LI>Right-click the field.
    <LI>Select Toggle Field Codes from the context menu.
    <LI>You'll see something like { DOCPROPERTY MyDate }.
    <LI>Before the closing bracket, insert a formatting switch @ "d MMM yyyy".
    <LI>In the above example, this would result in { DOCPROPERTY MyDate @ "d MMM yyyy" }.
    <LI>Right click the field and select Toggle Field Codes.
    <LI>Right click the field and select Update Field.[/list]Note: in date/time formats, M stands for month and m for minute.

Posting Permissions

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