Results 1 to 11 of 11
  1. #1
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Subdocument blues (Office 2000/XP/2003)

    I've got a problem (otherwise, why would I be writing this). My application requires two areas in the document that cannot be changed by the user--but it also requires that trackrevisions be set to TRUE. If I try to use sections and set ProtectedForForms=TRUE, I'm no longer able to use TrackRevisions. So I got around this by using locked subdocuments. However, now some of my users consistently crash when I (a) remove the subdocuments (which I must do before saving), and ([img]/forums/images/smilies/cool.gif[/img] save the doc as RTF. I know that subdocuments are notoriously flaky, but can't figure out another way to get around the problem. Anybody have any ideas?

    Thanks as always,

    Dan

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

    Re: Subdocument blues (Office 2000/XP/2003)

    You can turn on revision tracking before protecting the document for forms. It will still work.

    If you want the end user to be able to turn revision tracking on and off, you can create a macro that:
    - unprotect the document
    - toggles revision tracking on/off
    - reprotects the document
    and make this available to the user through a custom toolbar button and/or keyboard shortcut.

  3. #3
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subdocument blues (Office 2000/XP/2003)

    Thanks Hans! That's a huge help!

    Dan

  4. #4
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subdocument blues (Office 2000/XP/2003)

    I am noticing that there are actually a TON of things which are disabled in the Word menus when you protect a section--including, for instance, Edit->Copy/Paste (even though you can still use ctrl-C and ctrl-X, which makes no sense to me). At any rate, do I need to supply custom menu items for all of these functions? Also--I know no one here is responsible for it-- but I just don't understand the logic in turning off all these items just because one section of the document is protected. There's lots of the document which isn't protected. Does anyone know why they do this?

    Thanks...
    Dan

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

    Re: Subdocument blues (Office 2000/XP/2003)

    This has always been a sore point. My guess is that Microsoft wanted to create a mode in which the end user could basically only enter text (in form fields and in unprotected sections), but not modify the structure of the document. Unfortunately, this has turned out to be too restrictive for many applications.

    And yes, the only workaround is to create your own replacements for menu items and toolbar buttons that are disabled.

  6. #6
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subdocument blues (Office 2000/XP/2003)

    Some of my users may want to be able to record macros. I don't see any way to start that dialog from within my own macro. If I try this:

    Dialogs(wdDialogToolsMacroRecord).Show

    I get a message which says "This method or property is not available because a macro is currently running". Which raises the question: why is it there if you can't use it? Or is there a way to use it?

    Dan

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

    Re: Subdocument blues (Office 2000/XP/2003)

    That is only meant for use from another application, for example a COM add-in. It cannot be used from code running in Word itself.

    You can't record a macro in a protected document as far as I know, and letting users unprotect it in order to record a macro seems to be a certain recipe for disaster.

  8. #8
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subdocument blues (Office 2000/XP/2003)

    Hans--

    I understand your concerns about permitting them to record macros, but on balance--for reasons to complicated to go into here--I want to allow this. I've decided to bag protecting the forms and instead use the application_WindowSelectionChange event to prevent them from putting the cursor in the section I want to protect. The code looks like this:

    Private Sub m_appWord_WindowSelectionChange(ByVal Sel As Selection)
    Dim lStart As Long, lEnd As Long
    lStart = GetTickCount
    With Sel.Range
    If .InRange(m_rngSection1) Then
    m_rngSection2.Characters(1).Select
    Selection.Collapse
    End If
    End With
    lEnd = GetTickCount
    Debug.Print (lEnd - lStart) & " milliseconds"
    End Sub

    The code always appears to take less than a millisecond to execute, so it doesn't appear to be a big performance hit.

    BTW--I've been able to get the macro recorder dialog to pop up when I run it in an executable outside the Word process, but it doesn't seem to record anything. Here's how I call it. Am I doing it right?

    With appWord
    With .Dialogs(wdDialogToolsMacroRecord)
    .Show
    .Execute
    End With
    End With

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

    Re: Subdocument blues (Office 2000/XP/2003)

    Make sure that you have error handling throughout your code. If the user clicks Stop after an unhandled error, code execution would terminate and global variables would be cleared, leaving the document unprotected.

    About your BTW: I have never tried to run the macro recorder from an outside application (and I don't see any use for it), so I'm afraid I can't help you with that.

  10. #10
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subdocument blues (Office 2000/XP/2003)

    There is a way to combine the advantages of a protected document with form fields and the availability of all functionality of an unprotected document:

    Private Sub m_appWord_WindowSelectionChange(ByVal Sel As Selection)
    If ActiveDocument.Sections(Sel.Information(adActiveEn dSectionNumber)).ProtectedForForms = True Then
    ProtectionOn
    Else
    ProtectionOff
    End If
    End Sub

    Public Sub ProtectionOn()
    If Documents.Count < 1 Then Exit Sub
    If ActiveDocument.ProtectionType = wdNoProtection Then
    ActiveDocument.Protect Password:="YourSecret", NoReset:=True, Type:=wdAllowOnlyFormFields
    End If
    End Sub

    Public Sub ProtectionOff
    If Documents.Count < 1 Then Exit Sub
    If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect Password:="YourSecret"
    End If
    End Sub

    Of course you should add error-handling, especially to the WindowSelectionChange function.
    The effect of this function is, that it toggles document protection, depending on the protection status of each section. This works fine as long as your code doesn't do much manipulating (content of) form fields. When the cursor is in an unprotected section and for some reason the code reads/writes the content of a form field (ActiveDocument.FormFields("myFF").Result), Word behaves as if the form field is selected / the cursor is placed in that form field. This triggers the WindowSelectionChange function to protect the document, while the visible cursor is still in the unprotected section, confusing the user. Maybe there are work-arounds, i.e "remebering" the cursor position just before and explicitly return it to that position after reading/writing the content of a form field. But right now I'm onIy using this trick in documents with just 1 protected section containing form fields for the sole pupose of entering information from the user.

  11. #11
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subdocument blues (Office 2000/XP/2003)

    Thanks Jan. That's nice code. I'll keep it in mind, but at this point I'm inclined to use the solution I mentioned in my earlier post, because I do actually change the content of the protected section from time to time....Dan

Posting Permissions

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