Thread: [Solved] Insert Table with Tags
View Single Post
 
Old 11-21-2022, 03:16 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

What you want to do can't be done via the Insert Table dialogue box. You would need a separate macro to populate the table after you've created it. Alternatively, you could use a macro to both create and populate the table. The following macro takes the latter approach
Code:
Sub AddTable()
Application.ScreenUpdating = False
Dim StrNum As String, NumRows As Long, oTbl As Table, r As Long
StrNum = InputBox("How Many Pairs of Rows?")
If IsNumeric(StrNum) = False Then Exit Sub
NumRows = CLng(StrNum) * 2
Set oTbl = Selection.Tables.Add(Range:=Selection.Range, NumRows:=NumRows, NumColumns:=2)
With oTbl
  .Borders.Enable = True
  With .Range.ParagraphFormat
    .SpaceBefore = 0
    .SpaceAfter = 0
  End With
  If NumRows = 2 Then
    .Cell(1, 1).Range.Text = "<2FG>"
    .Cell(1, 2).Range.Text = "<2FG>"
    .Cell(2, 1).Range.Text = "<LLA>(a)"
    .Cell(2, 2).Range.Text = "<LLA>(b)"
  Else
    For r = 1 To NumRows Step 2
      .Cell(r, 1).Range.Text = "<4FG>"
      .Cell(r, 2).Range.Text = "<4FG>"
      .Cell(r + 1, 1).Range.Text = "<LLA>(" & Chr(96 + r) & ")"
      .Cell(r + 1, 2).Range.Text = "<LLA>(" & Chr(97 + r) & ")"
    Next
  End If
End With
Application.ScreenUpdating = True
End Sub
For PC macro installation & usage instructions, see: Installing Macros.
For Mac macro installation & usage instructions, see: Word:mac - Install a Macro.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote