![]() |
#13
|
|||
|
|||
![]()
Posting one last time to say, alternate solutions to my problem, to remove the bottom row of my table and add a row at the top, or to migrate the table rows down:
Migration solution (from macropod's macro): Code:
Sub MigrateReversed() Dim i As Long, j As Long, bRslt As Long Application.ScreenUpdating = False bRslt = MsgBox("Do you want to delete old data?", vbYesNo) If bRslt = vbNo Then Exit Sub With Selection.Tables(1) For i = .Rows.Count To 2 Step -1 For j = 1 To .Rows(i).Cells.Count If i > 2 Then .Cell(i, j).Range.FormFields(1).Result = _ .Cell(i - 1, j).Range.FormFields(1).Result Else .Cell(i, j).Range.FormFields(1).Result = "" End If Next Next End With Application.ScreenUpdating = True End Sub Code:
Sub AddRow() Dim oTable As Table Dim Response As String Dim CurRow As Row Dim i As Long Dim fCount As Long Dim ff As FormField Dim sPassword As String Set oTable = Selection.Tables(1) sPassword = "flower" 'Define the password used to protect the form (if any) Response = MsgBox("Do you want to delete the last row?", vbQuestion + vbYesNo) 'Ask user about deleting last row With ActiveDocument If Response = vbYes Then .Unprotect Password:=sPassword 'Unprotect document oTable.Rows(oTable.Rows.Count).Delete 'Delete last row .Protect NoReset:=True, Password:=sPassword, _ Type:=wdAllowOnlyFormFields 'Reprotect the form End If Response = MsgBox("Do you want to add a new row?", vbQuestion + vbYesNo) 'Ask user about adding new row If Response = vbYes Then .Unprotect Password:=sPassword 'Unprotect document Set CurRow = oTable.Rows.Add(BeforeRow:=oTable.Rows(2)) For i = 1 To CurRow.Cells.Count Set ff = .FormFields.Add(Range:=CurRow.Cells(i).Range, Type:=wdFieldFormTextInput) With ff .Name = "col" & i & "row2" 'Add a unique bookmark name .Enabled = True 'Enable the field for user entry .CalculateOnExit = True 'set the calculate on exit check box End With Next i .Protect NoReset:=True, Password:=sPassword, _ Type:=wdAllowOnlyFormFields 'Reprotect the form CurRow.Cells(1).Range.FormFields(1).Select 'Select the first field in the new row End If End With End Sub http://answers.microsoft.com/en-us/o...e-6bce18db44a2 As they do slightly different things, I am going to show both to the people who will be using my form and see which one they prefer. Thanks for all your help! I hope this is helpful to someone else also. Last edited by macropod; 04-08-2013 at 03:42 PM. Reason: Added code tags & formatting |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Elan05 | Word VBA | 23 | 09-11-2014 12:47 PM |
Mail Merge a Protected Form Maintaining Form Fills | t/korean85 | Word | 1 | 04-07-2013 05:34 PM |
![]() |
yessmarie | Word VBA | 1 | 05-25-2012 12:04 AM |
![]() |
DrDtMM | Word VBA | 12 | 01-23-2011 12:37 PM |
Font size changes in a protected form..? | jackbkmp | Word VBA | 0 | 03-03-2010 10:14 AM |