View Single Post
 
Old 03-15-2013, 09:21 AM
Elan05 Elan05 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Mar 2013
Posts: 13
Elan05 is on a distinguished road
Default Delete Rows in Protected Table with Form Fields

I am creating a document where the users will enter information in a table. I created a macro that allows the user to add rows as needed. I am trying to create a second macros that will run when the user exits the end of the table that will delete any rows that have all blank form fields.

I found this on another forum. I sent it to run when exiting the last form field of the table, the document flashes a few times so I can tell that it is running something but the blank rows did not delete. I am also not getting an error message. Can anyone help? What am I missing?!
Code:
Sub DeleteEmptyRows()
'
'Delete empty rows in the table after all equipment has been entered
'
ActiveDocument.Unprotect Password:="a"
Counter = ActiveDocument.Tables(1).Rows.Count
While Counter > 0
  If ActiveDocument.FormFields(Counter).Result = "" Then
    ActiveDocument.Tables(1).Rows(Counter).Delete
  End If
  Counter = Counter - 1
Wend
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="a"
End Sub

Last edited by macropod; 03-15-2013 at 05:08 PM. Reason: Added code tags & formatting
Reply With Quote