PDA

View Full Version : [SOLVED:] Automatic deletion of table rows in locked Word documents



Honne
01-29-2017, 11:04 AM
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

macropod
01-29-2017, 02:02 PM
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-vba/13955-macro-add-row-table-word-form.html#post38312
For code to a new row to a table in a document with content controls, see: http://www.msofficeforums.com/word-vba/13955-macro-add-row-table-word-form.html#post38461

gmaxey
01-30-2017, 06:57 AM
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

Honne
01-30-2017, 08:10 AM
Thanks GMaxey. This is exactly what I was looking for - PERFECT