none
Identifying Sections that are Protected RRS feed

  • Question

  • I'm unsure at what levels Word document protection can be identified. The following code -

     Dim nSections As Integer = objDoc.Sections.Count
     Dim i As Integer
     Debug.Print("# of sections in this document = " & nSections.ToString)
     For i = 1 To nSections
     If objDoc.Sections.Item(i).ProtectedForForms = True Then
     Debug.Print("Section " & objDoc.Sections.Item(i).Index.ToString & " is ProtectedForForms")
     Else
     Debug.Print("Section " & objDoc.Sections.Item(i).Index.ToString & " is not protected")
     End If
     Next
    

     

    gives me unexpected results when opening a sample document that has (on manual inspection) two sections, but none of them is actually a protected section.

    (My crude testing: debug output: "Section 1 is ProtectedForForms

                                                      Section 2 is not protected")

    However, another sample document, which I know to have Section 1 which IS protected, section 2 is not, gives the same result.

    Obviously, I'm confused about how to identify protected sections in Word docs. Can someone clarify this for me, please?


    [Edit]

    I may have an explanation for this, but would like corroboration and clarification.

    I’m guessing that this is due to a Macro that is withiin every document of the 50,000 i am dealing with. On (manually) opening with Word 2003, if I “Disable Macros" I can see a (password-protected) Macro “autoopen” in what I had called the “unprotected” documents, but if I “Enable Macros” then I see the “End of Protected Section” adornment on the Section Break.

    For the “protected” documents (Section 1 showing “End of Protected Section” whichever security mode is chosen), the Tools>Macros>Macros (Alt-F8) menu choice is greyed. But I assume the same autoopen macro is present.

    So I suspect that the explanation is that I need to explicitly set the security level for opening Word docs in my code – ie, by default it must be Low (whereas for testing by manually opening the docs in the installed Word 2003, I have it set to Medium). If the security is LOW then the code would detect Section #1 as a protected Section.

    I am using the Word 11.0 interop currently, and I'm wondering if the "security setting" (?) is more rigorous by default in Word 12.0 and 14.0.


    Tuesday, May 31, 2011 1:45 AM

Answers

  • The ProtectedForForms property is set by default but only relevant if the *document* ProtectionType is wdProtectionType.wdAllowOnlyFormFields. If the ProtectedForForms property has ever been explicitly set on a section, it will remain set after the protection is removed from the document but be meaningless.
     
     

    Enjoy,
    Tony
    www.WordArticles.com
    • Marked as answer by Ian Thomas Wednesday, June 1, 2011 12:07 AM
    Tuesday, May 31, 2011 8:23 AM

All replies

  • The ProtectedForForms property is set by default but only relevant if the *document* ProtectionType is wdProtectionType.wdAllowOnlyFormFields. If the ProtectedForForms property has ever been explicitly set on a section, it will remain set after the protection is removed from the document but be meaningless.
     
     

    Enjoy,
    Tony
    www.WordArticles.com
    • Marked as answer by Ian Thomas Wednesday, June 1, 2011 12:07 AM
    Tuesday, May 31, 2011 8:23 AM
  • I'll accept your Word, Tony! That sounds reasonable.

    Does it change with Word 2007, Word2010 (ie, is the section flag removed as a clean-up)?


    Ian Thomas
    Wednesday, June 1, 2011 12:07 AM
  • As far as I know it is the same in all versions of Word.
     

    Enjoy,
    Tony
    www.WordArticles.com
    Wednesday, June 1, 2011 8:29 AM