petedw
06-22-2005, 07:58 AM
Hi Guys,
I have a Macro that creates a table and then inserts a Formfield into each Cell.
I also require my macro to name each formfield (happy1, happy2 etc)
At the moment, it only names the Formfields in Column 1 and leaves the remaining ones without a name. :banghead:
Please take a look at my code and see if you can fix this for me.
Sub maketable()
Dim tbl As Table, rng As Range, titlerow As Row, FFName As Integer
Dim cCells As Integer, cColumns As Integer, cRows As Integer, counter As Integer
cColumns = 4
FFName = 1
'Dialog box for number of payments
cCells = Val(InputBox("Enter number of payments"))
cCells = cCells * 2
If cCells = 0 Then Exit Sub
cRows = Fix(cCells / cColumns)
If (cCells Mod cColumns) <> 0 Then cRows = cRows + 1
'Draws Table
Set rng = ActiveDocument.Bookmarks("PmtTable").Range
rng.Collapse direction:=wdCollapseEnd
ActiveDocument.Unprotect
ActiveDocument.Bookmarks("PmtTable").Select
Set tbl = Selection.Tables.Add(rng, cRows, cColumns)
'fills table
For ffcolloop = 1 To cColumns
'Date Columns
For FFRowLoop = 1 To cRows
tbl.Cell(FFRowLoop, ffcolloop).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
Selection.PreviousField.Select
'If FFName = 1 Then
With Selection.FormFields("text1")
.Name = "Happy" & FFName
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
End With
FFName = FFName + 1
Next ffcolloop
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset
End Sub
Many Thanks
Pete
I have a Macro that creates a table and then inserts a Formfield into each Cell.
I also require my macro to name each formfield (happy1, happy2 etc)
At the moment, it only names the Formfields in Column 1 and leaves the remaining ones without a name. :banghead:
Please take a look at my code and see if you can fix this for me.
Sub maketable()
Dim tbl As Table, rng As Range, titlerow As Row, FFName As Integer
Dim cCells As Integer, cColumns As Integer, cRows As Integer, counter As Integer
cColumns = 4
FFName = 1
'Dialog box for number of payments
cCells = Val(InputBox("Enter number of payments"))
cCells = cCells * 2
If cCells = 0 Then Exit Sub
cRows = Fix(cCells / cColumns)
If (cCells Mod cColumns) <> 0 Then cRows = cRows + 1
'Draws Table
Set rng = ActiveDocument.Bookmarks("PmtTable").Range
rng.Collapse direction:=wdCollapseEnd
ActiveDocument.Unprotect
ActiveDocument.Bookmarks("PmtTable").Select
Set tbl = Selection.Tables.Add(rng, cRows, cColumns)
'fills table
For ffcolloop = 1 To cColumns
'Date Columns
For FFRowLoop = 1 To cRows
tbl.Cell(FFRowLoop, ffcolloop).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
Selection.PreviousField.Select
'If FFName = 1 Then
With Selection.FormFields("text1")
.Name = "Happy" & FFName
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
End With
FFName = FFName + 1
Next ffcolloop
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset
End Sub
Many Thanks
Pete