none
Prevent the user from adding additional rows to the table. RRS feed

  • Question

  • Hi All,

     I have a table that I insert into the Document like this

     oTable = oDoc.Tables.Add(range, 10, 3, DefaultTableBehavior: Word.WdDefaultTableBehavior.wdWord9TableBehavior, AutoFitBehavior: Type.Missing);

    Here I want  to limit a user to only ten rows, nothing more .Is there a way to prevent the user from adding more rows via ms word default options like 

    1)Right click --> Insert -->insert row above/below

    2) Layout --> Insert -->row above below? 

    How to limit the user from adding extra rows to my table ?

    Any help is appreciated.Thanks in advance!

    Thursday, February 19, 2015 5:35 AM

Answers

  • Protecting the document is as simple as:

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields

    However, you'll still need to add content controls or formfields to the table so it can be filled in, where appropriate, and to any other parts of the document where you want the users to add content. For example, to add text content controls to the first table in the document, you might use code like:

    Sub Demo()
    Dim TblCell As Cell
    With ActiveDocument
      For Each TblCell In .Tables(1).Range.Cells
        .ContentControls.Add wdContentControlText, TblCell.Range
      Next
      .Protect Type:=wdAllowOnlyFormFields
    End With
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, February 19, 2015 7:56 AM

All replies

  • You can do that by applying 'filling in forms' editing restrictions to the document, but not via 'read-only' editing restrictions. Even if you apply read-only editing restrictions and mark just the table cells as exceptions, your users will be able to add new rows via Table Tools>Layout>Insert Above (or Insert below). Applying 'filling in forms' editing restrictions to the document means your users will only be able to use formfields and/or content controls in the document, unless you leave an entire Section unprotected (e.g. you could insert Section breaks either side of the table and apply the  'filling in forms' editing restrictions to only the Section containing the table).

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, February 19, 2015 5:59 AM
  • Thanks a lot for the reply Paul , but this is an application level add in , can I make some setting changes in my code, if yes then can you please elaborate ?
    Thursday, February 19, 2015 6:17 AM
  • Protecting the document is as simple as:

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields

    However, you'll still need to add content controls or formfields to the table so it can be filled in, where appropriate, and to any other parts of the document where you want the users to add content. For example, to add text content controls to the first table in the document, you might use code like:

    Sub Demo()
    Dim TblCell As Cell
    With ActiveDocument
      For Each TblCell In .Tables(1).Range.Cells
        .ContentControls.Add wdContentControlText, TblCell.Range
      Next
      .Protect Type:=wdAllowOnlyFormFields
    End With
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, February 19, 2015 7:56 AM