Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
I'm creating a form with a table and would like to be able to add rows to the
protected form. The saved form would have one or two rows, and the user could add as many rows as needed to the table. Does anyone know how to do this? |
#2
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Here's a macro that does that, showing how to deal with varying types of
formfields in the row: ' Macro created 02/02/03 by Doug Robbins ' To add a new row to a table containing formfields in every column ' automatically on exit from the last cell in the present last row of the Table Dim rownum As Long, i As Long Dim Response Response = MsgBox("Do you need to add another row to the table?", _ vbYesNo + vbQuestion + vbDefaultButton2, "Add another Row") If Response = vbYes Then ' User chose Yes. With ActiveDocument .Unprotect With Selection.Tables(1) .Rows.Add rownum = .Rows.Count For i = 1 To .Columns.Count ActiveDocument.FormFields.Add Range:=.Cell(rownum,i).Range, _ Type:=wdFieldFormTextInput Next i .Cell(.Rows.Count, .Columns.Count).Range.FormFields _ (1).ExitMacro = "addRow" .Cell(.Rows.Count, 1).Range.FormFields(1).Select End With .Protect Type:=wdAllowOnlyFormFields, NoReset:=True End With Else ' User chose No. Exit Sub End If -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "CSC" wrote in message ... I'm creating a form with a table and would like to be able to add rows to the protected form. The saved form would have one or two rows, and the user could add as many rows as needed to the table. Does anyone know how to do this? |
#3
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
What if your table row contains Drop down form fields and check box form
fields? Your solution only adds empty text form fields. I would like to have a macro that determined what the column had and repeated it for the next column. The only solution I have come up with is leaving a blank row and then copying that row. This works but if the users need to insert a row in the middle it will copy the below row. |
#4
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
I figured this out by playing around a bit. The below code will create a new
row in a table with the same field types. So if the table contain text, drop down or check boxs does not matter. It also brings in all the selection options from the drop down and set it to the first item in the drop down. Sub addrow3() ' Macro created 04/07/03 by Ross Vanevenhoven ' To add a new row to a table containing text, Drop Down or Check formfields in every column ' automatically on exit from the last cell in the present last row of the Table Dim rownum As Integer, i As Integer response = MsgBox("Do you need another row?", 36, "Add Row") If response = vbYes Then ActiveDocument.Unprotect With Selection.Tables(1) FormFieldsCount = .Range.FormFields.Count .Rows.Add rownum = .Rows.Count For i = 1 To .Columns.Count Select Case .Range.FormFields(i).Type Case wdFieldFormTextInput .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormTextInput Case wdFieldFormDropDown .Cell(rownum - 1, i).Range.Copy .Cell(rownum, i).Range.Paste .Range.FormFields(FormFieldsCount + i).DropDown.Value = 1 Case wdFieldFormCheckBox .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormCheckBox End Select Next i .Cell(.Rows.Count, 1).Range.FormFields(1).Select .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" End With ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If End Sub |
#5
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Ross:
When I use this code I get a "Bad parameter" error message on the following line: .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" It adds the row but because it doesn't exit the macro it won't add any additional lines. Please help! Thanks, "Ross" wrote: I figured this out by playing around a bit. The below code will create a new row in a table with the same field types. So if the table contain text, drop down or check boxs does not matter. It also brings in all the selection options from the drop down and set it to the first item in the drop down. Sub addrow3() ' Macro created 04/07/03 by Ross Vanevenhoven ' To add a new row to a table containing text, Drop Down or Check formfields in every column ' automatically on exit from the last cell in the present last row of the Table Dim rownum As Integer, i As Integer response = MsgBox("Do you need another row?", 36, "Add Row") If response = vbYes Then ActiveDocument.Unprotect With Selection.Tables(1) FormFieldsCount = .Range.FormFields.Count .Rows.Add rownum = .Rows.Count For i = 1 To .Columns.Count Select Case .Range.FormFields(i).Type Case wdFieldFormTextInput .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormTextInput Case wdFieldFormDropDown .Cell(rownum - 1, i).Range.Copy .Cell(rownum, i).Range.Paste .Range.FormFields(FormFieldsCount + i).DropDown.Value = 1 Case wdFieldFormCheckBox .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormCheckBox End Select Next i .Cell(.Rows.Count, 1).Range.FormFields(1).Select .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" End With ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If End Sub |
#6
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
The line should read
..Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" This editor raps around some times. "Worsty" wrote: Ross: When I use this code I get a "Bad parameter" error message on the following line: .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" It adds the row but because it doesn't exit the macro it won't add any additional lines. Please help! Thanks, "Ross" wrote: I figured this out by playing around a bit. The below code will create a new row in a table with the same field types. So if the table contain text, drop down or check boxs does not matter. It also brings in all the selection options from the drop down and set it to the first item in the drop down. Sub addrow3() ' Macro created 04/07/03 by Ross Vanevenhoven ' To add a new row to a table containing text, Drop Down or Check formfields in every column ' automatically on exit from the last cell in the present last row of the Table Dim rownum As Integer, i As Integer response = MsgBox("Do you need another row?", 36, "Add Row") If response = vbYes Then ActiveDocument.Unprotect With Selection.Tables(1) FormFieldsCount = .Range.FormFields.Count .Rows.Add rownum = .Rows.Count For i = 1 To .Columns.Count Select Case .Range.FormFields(i).Type Case wdFieldFormTextInput .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormTextInput Case wdFieldFormDropDown .Cell(rownum - 1, i).Range.Copy .Cell(rownum, i).Range.Paste .Range.FormFields(FormFieldsCount + i).DropDown.Value = 1 Case wdFieldFormCheckBox .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormCheckBox End Select Next i .Cell(.Rows.Count, 1).Range.FormFields(1).Select .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" End With ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If End Sub |
#7
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Ross:
That is what I have in my code and it is in all one line. I don't get a compile error I get a "bad parameter" thanks, "Ross" wrote: The line should read .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" This editor raps around some times. "Worsty" wrote: Ross: When I use this code I get a "Bad parameter" error message on the following line: .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" It adds the row but because it doesn't exit the macro it won't add any additional lines. Please help! Thanks, "Ross" wrote: I figured this out by playing around a bit. The below code will create a new row in a table with the same field types. So if the table contain text, drop down or check boxs does not matter. It also brings in all the selection options from the drop down and set it to the first item in the drop down. Sub addrow3() ' Macro created 04/07/03 by Ross Vanevenhoven ' To add a new row to a table containing text, Drop Down or Check formfields in every column ' automatically on exit from the last cell in the present last row of the Table Dim rownum As Integer, i As Integer response = MsgBox("Do you need another row?", 36, "Add Row") If response = vbYes Then ActiveDocument.Unprotect With Selection.Tables(1) FormFieldsCount = .Range.FormFields.Count .Rows.Add rownum = .Rows.Count For i = 1 To .Columns.Count Select Case .Range.FormFields(i).Type Case wdFieldFormTextInput .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormTextInput Case wdFieldFormDropDown .Cell(rownum - 1, i).Range.Copy .Cell(rownum, i).Range.Paste .Range.FormFields(FormFieldsCount + i).DropDown.Value = 1 Case wdFieldFormCheckBox .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormCheckBox End Select Next i .Cell(.Rows.Count, 1).Range.FormFields(1).Select .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" End With ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If End Sub |
#8
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Do you have any merged cells in your table?
-- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Worsty" wrote in message ... Ross: That is what I have in my code and it is in all one line. I don't get a compile error I get a "bad parameter" thanks, "Ross" wrote: The line should read .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" This editor raps around some times. "Worsty" wrote: Ross: When I use this code I get a "Bad parameter" error message on the following line: .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" It adds the row but because it doesn't exit the macro it won't add any additional lines. Please help! Thanks, "Ross" wrote: I figured this out by playing around a bit. The below code will create a new row in a table with the same field types. So if the table contain text, drop down or check boxs does not matter. It also brings in all the selection options from the drop down and set it to the first item in the drop down. Sub addrow3() ' Macro created 04/07/03 by Ross Vanevenhoven ' To add a new row to a table containing text, Drop Down or Check formfields in every column ' automatically on exit from the last cell in the present last row of the Table Dim rownum As Integer, i As Integer response = MsgBox("Do you need another row?", 36, "Add Row") If response = vbYes Then ActiveDocument.Unprotect With Selection.Tables(1) FormFieldsCount = .Range.FormFields.Count .Rows.Add rownum = .Rows.Count For i = 1 To .Columns.Count Select Case .Range.FormFields(i).Type Case wdFieldFormTextInput .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormTextInput Case wdFieldFormDropDown .Cell(rownum - 1, i).Range.Copy .Cell(rownum, i).Range.Paste .Range.FormFields(FormFieldsCount + i).DropDown.Value = 1 Case wdFieldFormCheckBox .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormCheckBox End Select Next i .Cell(.Rows.Count, 1).Range.FormFields(1).Select .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" End With ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If End Sub |
#9
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Doug:
I got this code to work, but the problem is now that I need some way to NOT keep adding rows. I tried to add the "Yes" No" functionality, but that is when I get the error. Any help would be appreciated: Dim rownum As Long, i As Long, j As Long Dim oRng As Word.Range Dim pListArray() As String Dim pType As String Dim myField As FormField Dim oTbl As Table Dim Response 'Response = MsgBox("Do you need to add another row to the table?", _ 'vbYesNo + vbQuestion + vbDefaultButton2, "Add another Row") 'If Response = vbYes Then Set oTbl = Selection.Tables(1) ActiveDocument.Unprotect oTbl.Rows.Add rownum = oTbl.Rows.Count For i = 1 To oTbl.Columns.Count Set oRng = oTbl.Cell(rownum, i).Range oRng.Collapse wdCollapseStart pType = oTbl.Cell(rownum - 1, i).Range.FormFields(1).Type Select Case pType Case 83 'Constant for a dropdown Set myField = ActiveDocument.FormFields.Add(Range:=oRng, _ Type:=wdFieldFormDropDown) For j = 1 To oTbl.Cell(rownum - 1, i).Range.FormFields(1).DropDown.ListEntries.Count ReDim Preserve pListArray(j) pListArray(j) = oTbl.Cell(rownum - 1, i).Range.FormFields(1).DropDown.ListEntries(j).Nam e Next j For j = 1 To UBound(pListArray) myField.DropDown.ListEntries.Add pListArray(j) Next j Case 70 'Constant for a textfield ActiveDocument.FormFields.Add Range:=oRng, _ Type:=wdFieldFormTextInput Case 71 'Constant for a checkbox ActiveDocument.FormFields.Add Range:=oRng, _ Type:=wdFieldFormCheckBox End Select Next i oTbl.Cell(oTbl.Rows.Count, oTbl.Columns.Count).Range.FormFields(1).ExitMacro = "Gregaddrows" oTbl.Cell(oTbl.Rows.Count, 1).Range.FormFields(1).Select ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True "Doug Robbins - Word MVP" wrote: Do you have any merged cells in your table? -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Worsty" wrote in message ... Ross: That is what I have in my code and it is in all one line. I don't get a compile error I get a "bad parameter" thanks, "Ross" wrote: The line should read .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" This editor raps around some times. "Worsty" wrote: Ross: When I use this code I get a "Bad parameter" error message on the following line: .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" It adds the row but because it doesn't exit the macro it won't add any additional lines. Please help! Thanks, "Ross" wrote: I figured this out by playing around a bit. The below code will create a new row in a table with the same field types. So if the table contain text, drop down or check boxs does not matter. It also brings in all the selection options from the drop down and set it to the first item in the drop down. Sub addrow3() ' Macro created 04/07/03 by Ross Vanevenhoven ' To add a new row to a table containing text, Drop Down or Check formfields in every column ' automatically on exit from the last cell in the present last row of the Table Dim rownum As Integer, i As Integer response = MsgBox("Do you need another row?", 36, "Add Row") If response = vbYes Then ActiveDocument.Unprotect With Selection.Tables(1) FormFieldsCount = .Range.FormFields.Count .Rows.Add rownum = .Rows.Count For i = 1 To .Columns.Count Select Case .Range.FormFields(i).Type Case wdFieldFormTextInput .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormTextInput Case wdFieldFormDropDown .Cell(rownum - 1, i).Range.Copy .Cell(rownum, i).Range.Paste .Range.FormFields(FormFieldsCount + i).DropDown.Value = 1 Case wdFieldFormCheckBox .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormCheckBox End Select Next i .Cell(.Rows.Count, 1).Range.FormFields(1).Select .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" End With ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If End Sub |
#10
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Your code is missing
Else ' User chose No. Exit Sub End If -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Worsty" wrote in message ... Doug: I got this code to work, but the problem is now that I need some way to NOT keep adding rows. I tried to add the "Yes" No" functionality, but that is when I get the error. Any help would be appreciated: Dim rownum As Long, i As Long, j As Long Dim oRng As Word.Range Dim pListArray() As String Dim pType As String Dim myField As FormField Dim oTbl As Table Dim Response 'Response = MsgBox("Do you need to add another row to the table?", _ 'vbYesNo + vbQuestion + vbDefaultButton2, "Add another Row") 'If Response = vbYes Then Set oTbl = Selection.Tables(1) ActiveDocument.Unprotect oTbl.Rows.Add rownum = oTbl.Rows.Count For i = 1 To oTbl.Columns.Count Set oRng = oTbl.Cell(rownum, i).Range oRng.Collapse wdCollapseStart pType = oTbl.Cell(rownum - 1, i).Range.FormFields(1).Type Select Case pType Case 83 'Constant for a dropdown Set myField = ActiveDocument.FormFields.Add(Range:=oRng, _ Type:=wdFieldFormDropDown) For j = 1 To oTbl.Cell(rownum - 1, i).Range.FormFields(1).DropDown.ListEntries.Count ReDim Preserve pListArray(j) pListArray(j) = oTbl.Cell(rownum - 1, i).Range.FormFields(1).DropDown.ListEntries(j).Nam e Next j For j = 1 To UBound(pListArray) myField.DropDown.ListEntries.Add pListArray(j) Next j Case 70 'Constant for a textfield ActiveDocument.FormFields.Add Range:=oRng, _ Type:=wdFieldFormTextInput Case 71 'Constant for a checkbox ActiveDocument.FormFields.Add Range:=oRng, _ Type:=wdFieldFormCheckBox End Select Next i oTbl.Cell(oTbl.Rows.Count, oTbl.Columns.Count).Range.FormFields(1).ExitMacro = "Gregaddrows" oTbl.Cell(oTbl.Rows.Count, 1).Range.FormFields(1).Select ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True "Doug Robbins - Word MVP" wrote: Do you have any merged cells in your table? -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Worsty" wrote in message ... Ross: That is what I have in my code and it is in all one line. I don't get a compile error I get a "bad parameter" thanks, "Ross" wrote: The line should read .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" This editor raps around some times. "Worsty" wrote: Ross: When I use this code I get a "Bad parameter" error message on the following line: .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" It adds the row but because it doesn't exit the macro it won't add any additional lines. Please help! Thanks, "Ross" wrote: I figured this out by playing around a bit. The below code will create a new row in a table with the same field types. So if the table contain text, drop down or check boxs does not matter. It also brings in all the selection options from the drop down and set it to the first item in the drop down. Sub addrow3() ' Macro created 04/07/03 by Ross Vanevenhoven ' To add a new row to a table containing text, Drop Down or Check formfields in every column ' automatically on exit from the last cell in the present last row of the Table Dim rownum As Integer, i As Integer response = MsgBox("Do you need another row?", 36, "Add Row") If response = vbYes Then ActiveDocument.Unprotect With Selection.Tables(1) FormFieldsCount = .Range.FormFields.Count .Rows.Add rownum = .Rows.Count For i = 1 To .Columns.Count Select Case .Range.FormFields(i).Type Case wdFieldFormTextInput .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormTextInput Case wdFieldFormDropDown .Cell(rownum - 1, i).Range.Copy .Cell(rownum, i).Range.Paste .Range.FormFields(FormFieldsCount + i).DropDown.Value = 1 Case wdFieldFormCheckBox .Cell(rownum, i).Range.FormFields.Add Range:=.Cell(rownum, i).Range, Type:=wdFieldFormCheckBox End Select Next i .Cell(.Rows.Count, 1).Range.FormFields(1).Select .Cell(.Rows.Count, .Columns.Count).Range.FormFields(1).ExitMacro = "addrow3" End With ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If End Sub |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Word 2007 tables - adding multiple rows | Microsoft Word Help | |||
word and forms: updating a table by adding more rows | Microsoft Word Help | |||
Adding Shaded Rows between Rows | Tables | |||
'Tables'- 2 columns,4 rows. Can you merge one column into 3 rows? | Tables | |||
Rows adding to Tables | Microsoft Word Help |