Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » VBA(Excel, Word, etc...) » Need code for expanding Word table rows with...


Need code for expanding Word table rows with...Expand / Collapse
Author
Message
Posted 1/19/2010 3:34:52 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 2/1/2010 9:49:56 AM
Posts: 1, Visits: 9
I'm working on a Word template (form) that contains tables having a mix of formfields such as textinput, dropdowns, and checkboxes.  I would like to provide a single default data row for each table, but if the user enters valid data in the first cell of the last row, the table expands with a new default row below the active cell the user just filled in. The following code is latest draft for a table where default textinput for cell(1) is "nn", but requires at least two data rows and is not smart enough to know if another default row is available below the active (selected) cell:

Sub AddRow()
    Dim thisDoc As Document
    Set thisDoc = ActiveDocument
    Dim oTable As Table
    Dim oCell As Cell
    Dim oPrevRow As Row, oNewRow As Row
    Dim tmp
    'Unprotect Document
    If thisDoc.ProtectionType <> wdNoProtection Then
        thisDoc.Unprotect
    End If
   
    tmp = Selection.Text
    If tmp <> "nn" Then
        If tmp <> "n" Then
        'Selection.FormFields(1).TextInput.Clear
            ' Copy last row
            Set oTable = thisDoc.Tables(10)
            Set oPrevRow = oTable.Rows(oTable.Rows.Count)
            oPrevRow.Range.Copy
            Set oNewRow = oTable.Rows(oTable.Rows.Count)
            ' Copy last row to new row
            oNewRow.Range.Paste
           
        End If
    End If
    'Protect Document
    If thisDoc.ProtectionType = wdNoProtection Then
        thisDoc.Protect wdAllowOnlyFormFields, NoReset:=True
    End If
End Sub

I also would like to ensure that the formfields in the new row are reset to their default values without resetting the entire form.

Post #28712
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 6:48pm