View Single Post
 
Old 01-11-2017, 06:08 PM
Pindar Pindar is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jan 2017
Posts: 12
Pindar is on a distinguished road
Default

The table is set to have fixed width, and when following your string of clicks, "automatically resize to fit contents" is not checked. Your sample table also works instantly for me, but my form does not. If there is no fix, that is fine. It's already much faster than adding a row manually.

I have one more issue though. Running the macro causes the first box at the top of the document to be selected. I want the first box in the new row to be selected instead. I tried and failed to fix this by editing the very end of your code here:
Code:
 Option Explicit

Sub AddRow()
Application.ScreenUpdating = False
'This macro adds another row to the table.
' If you need the formfields named, activate the commented-out code.
' As coded, the formfield names assume each column uses a different formfield
' name ending in a two-digit number corresponding to the formfield row. For
' example, formfield names on tabe row 2, which is formfield row 1, end with 01.
Dim i As Long, j As Long, FmFld As FormField, Prot As Variant
'Dim StrNms As String
Const Pwd As String = "pswrd" 'Insert password here
With Selection
  i = .Tables(1).Range.FormFields.Count
  j = ActiveDocument.Range(.Tables(1).Range.Start, .Range.End).FormFields.Count
End With
If i = j Then
  If MsgBox("Add new row?", vbQuestion + vbYesNo) = vbYes Then
    With ActiveDocument
      Prot = .ProtectionType
      If .ProtectionType <> wdNoProtection Then
        Prot = .ProtectionType
        .Unprotect Password:=Pwd
      End If
      With Selection.Tables(1).Rows
        i = .Count
        With .Last.Range
          'For Each FmFld In .FormFields
            'StrNms = StrNms & "|" & Left(FmFld.Name, Len(FmFld.Name) - 2) & Format(i, "00")
          'Next
          .Next.InsertBefore vbCr
          .Next.FormattedText = .FormattedText
        End With
        With .Last.Range.FormFields
          For i = 1 To .Count
            With .Item(i)
              If .Type = wdFieldFormCheckBox Then .CheckBox.Value = False
              If .Type = wdFieldFormTextInput Then .TextInput.Clear
              If .Type = wdFieldFormDropDown Then .DropDown.Value = .DropDown.Default
              '.Select
              'With Dialogs(wdDialogFormFieldOptions)
                '.Name = Split(StrNms, "|")(i)
                '.Execute
              'End With
            End With
          Next
          .Item(1).Select
        End With
      End With
      .Protect Type:=Prot, Password:=Pwd, Noreset:=True
    End With
  End If
End If
Application.ScreenUpdating = True
Call Macro1
End Sub
Code:
 Sub Macro1()
'
' Macro1 Macro
' test, go to paart number after add line
'

Selection.EndKey Unit:=wdStory
Selection.MoveLeft Unit:=wdCharacter, Count:=45

End Sub

Last edited by Pindar; 01-11-2017 at 10:35 PM.
Reply With Quote