Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Tables / October 2006

Tip: Looking for answers? Try searching our database.

Assing Styles to the forms created in a table of Word .Dot file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arthi - 31 Oct 2006 15:55 GMT
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).Range
   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).Range
   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).Range
   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
Doug Robbins - Word MVP - 31 Oct 2006 20:39 GMT
Try

Private Sub Station_Click()
Dim oFormfield As FormField
Dim sText As String
Dim oRange As Range
Dim iCount As Long
Dim icell As Long
sText = ""
With ActiveDocument
   'unprotect file
   .Unprotect Password:=""
   'get current number of Rows:
   iCount = .Tables(2).Rows.Count
   If (iCount < 6) Then 'Add row
       .Tables(2).Rows.Add
       iCount = iCount + 1
       For icell = 1 To 3
           Set oRange = .Tables(2).Cell(iCount, icell).Range
           Set oFormfield = ActiveDocument.FormFields.Add(Range:=oRange, _
           Type:=wdFieldFormTextInput)
           With oFormfield
               .TextInput.Default = sText
           End With
           oRange.Style = .Styles("Station")
       Next
   Else
       MsgBox ("No more rows can be created")
   End If
   'Reprotect file
   .Protect wdAllowOnlyFormFields, NoReset:=True
End With

End Sub

Signature

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

>i need to add a row to a existing table(with 3 coloums)  by cliking a
>button
[quoted text clipped - 77 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.