Assing Styles to the forms created in a table of Word .Dot file
i need to add a row to a existing table(with 3 coloums) by cliking a button
on the word doc.Then create from field in each coloums in the row and assign
styles to each form field.
Below is the code i have writtem , it assingns stylles only to the form
field in the frist coloumn , n other form fields are assigned style of the
type the table header is.....
Private Sub Station_Click()
With ActiveDocument
'unprotect file
ActiveDocument.Unprotect Password:=""
'get current number of Rows:
Dim iCount As Integer
Dim iCell As Integer
'Add row
iCount = ActiveDocument.Tables(2).Rows.Count
If (iCount 6) Then
ActiveDocument.Tables(2).Rows.Add
Dim oFormfield As FormField
Dim sName As String
Dim sText As String
Dim oRange As Range
sText = ""
sName = ""
iCount = iCount + 1
Set oRange = ActiveDocument.Tables(2).Rows(iCount).Cells(1).Ran ge
Set oFormfield = ActiveDocument.FormFields.Add(Range:=oRange,
Type:=wdFieldFormTextInput)
sText = ""
With oFormfield
.TextInput.Default = sText
.Select
Selection.Style = ActiveDocument.Styles("Station")
End With
Set oRange = ActiveDocument.Tables(2).Rows(iCount).Cells(2).Ran ge
Set oFormfield = ActiveDocument.FormFields.Add(Range:=oRange,
Type:=wdFieldFormTextInput)
sText = ""
With oFormfield
.TextInput.Default = sText
.Select
Selection.Style = ActiveDocument.Styles("Station")
End With
Set oRange = ActiveDocument.Tables(2).Rows(iCount).Cells(3).Ran ge
Set oFormfield = ActiveDocument.FormFields.Add(Range:=oRange,
Type:=wdFieldFormTextInput)
sText = ""
With oFormfield
.TextInput.Default = sText
.Select
Selection.Style = ActiveDocument.Styles("Station")
End With
Else
MsgBox ("No more rows can be created")
End If
'Reprotect file
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
End With
End Sub
|