locked
Lock text selection in word 2003 (VBA) RRS feed

  • Question

  • Hi,

     

    I need to lock some text area (Selection) in Word 2003. I've solved this problem in Word 2007+ (docx) as follows:

    ' groupselection
    oW.Selection.Range.ContentControls.Add wdContentControlGroup  
    ' lock content
    oW.Selection.Range.ParentContentControl.LockContentControl = True
    oW.Selection.Range.ParentContentControl.LockContents = True
    
    ' lock document
    


    These functions not supported in Word 2003.

     

    Can I ask you for advice if there is any solution?

     

    Best regards

     

    Michal

    Thursday, November 10, 2011 11:19 AM

Answers

  • Hi jezzek

    <<but I need lock for changes only specific text selection not all document.>>

    In that case you need to insert *section breaks* before and after the text that should be protected. In Word 2003 I believe you'll find them in the Insert menu (Insert break), and you want the type "continuous".

    Then, in the Protect Document dialog box (Tools menu) you should find a button labelled "Sections" that gives you a list of sections in the document with checkboxes next to them. As I recall, you need to remove the checkmark from the sections that should not be protected.

    There's a "gotcha" to all of this, however: even in a document with unprotected sections some kinds of editing are not possible as long as the document is protected. The user can't work with "floating" graphics, nor edit the header/footer, for example.

    Word 2003 simply doesn't have an equivalent to the 2007 content controls functionality - there are reasons for new versions :-).


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Shasur Friday, November 11, 2011 12:11 PM
    • Marked as answer by jezikk Friday, November 11, 2011 1:49 PM
    Friday, November 11, 2011 9:34 AM

All replies

  • Have you tried protecting the document / parts of the document in Word 2003

    Cheers

    Shasur


    http://www.vbadud.blogspot.com http://www.dotnetdud.blogspot.com
    Thursday, November 10, 2011 11:27 AM
  • Thank you for quick response.

     

    Please, how can I do this in VBA? I can't find any relevant source.

     

    Michal

    Thursday, November 10, 2011 12:17 PM
  • Please, how can I do this in VBA? I can't find any relevant source.


    Document.Protect Type:=wdAllowOnlyFormFields
    Cindy Meister, VSTO/Word MVP
    Friday, November 11, 2011 7:36 AM
  • Friday, November 11, 2011 7:37 AM
  • Ok, but I need lock for changes only specific text selection not all document. This selection must be locked against any editing (read only) and rest of the document using Document.ProtectionType.

    In Word 2007+ I lock specific selection using:

    ' groupselection
    oW.Selection.Range.ContentControls.Add wdContentControlGroup  
    ' lock content
    oW.Selection.Range.ParentContentControl.LockContentControl = True
    oW.Selection.Range.ParentContentControl.LockContents = True

    
    
    and then I lock document. But this methods is not supported in Word 2003, so I looking for another solution.

    Friday, November 11, 2011 9:21 AM
  • Hi jezzek

    <<but I need lock for changes only specific text selection not all document.>>

    In that case you need to insert *section breaks* before and after the text that should be protected. In Word 2003 I believe you'll find them in the Insert menu (Insert break), and you want the type "continuous".

    Then, in the Protect Document dialog box (Tools menu) you should find a button labelled "Sections" that gives you a list of sections in the document with checkboxes next to them. As I recall, you need to remove the checkmark from the sections that should not be protected.

    There's a "gotcha" to all of this, however: even in a document with unprotected sections some kinds of editing are not possible as long as the document is protected. The user can't work with "floating" graphics, nor edit the header/footer, for example.

    Word 2003 simply doesn't have an equivalent to the 2007 content controls functionality - there are reasons for new versions :-).


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Shasur Friday, November 11, 2011 12:11 PM
    • Marked as answer by jezikk Friday, November 11, 2011 1:49 PM
    Friday, November 11, 2011 9:34 AM