Consulting

Results 1 to 4 of 4

Thread: Automatic deletion of table rows in locked Word documents

  1. #1
    VBAX Newbie
    Joined
    Jan 2017
    Posts
    2
    Location

    Automatic deletion of table rows in locked Word documents

    Hello.

    I hope someone can help me. I have a word template with text form fields. In this document, there is a table with 3 columns. In the third column there is a text field in each line which is filled with a number. If the persons have filled the respective lines, the lines should be automatically deleted where no entry exists in the text field.

    The first column contains an article description. In the second column a package unit and in the third column are the text form fields where the number is entered. The form is blocked for the people of the house and should be unlocked by a button afterwards and be blocked again after the delete.

    Please help.

    Thank you

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    What would cause this process to run? An alternative approach would be to start off with the minimum number of rows required, then add rows as needed.

    For code to a new row to a table in a document with formfields, see: http://www.msofficeforums.com/word-v...html#post38312
    For code to a new row to a table in a document with content controls, see: http://www.msofficeforums.com/word-v...html#post38461



    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    How you run it is up to you:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim lngIndex As Long
      If ActiveDocument.ProtectionType <> wdNoProtection Then
        ActiveDocument.Unprotect Password:=""
      End If
      For lngIndex = ActiveDocument.Tables(1).Rows.Count To 1 Step -1
        If Not (IsNumeric(ActiveDocument.Tables(1).Cell(lngIndex, 3).Range.FormFields(1).Result)) Then
          ActiveDocument.Tables(1).Rows(lngIndex).Delete
        End If
      Next
      ActiveDocument.Protect wdAllowOnlyFormFields, True, ""
    lbl_Exit:
      Exit Sub
      
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    VBAX Newbie
    Joined
    Jan 2017
    Posts
    2
    Location
    Thanks GMaxey. This is exactly what I was looking for - PERFECT

Posting Permissions

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