Home > other >  How to use VBA to format a table at endnotes in Microsoft word?
How to use VBA to format a table at endnotes in Microsoft word?

Time:06-06

How can we use VBA to format only tables at endnotes in Microsoft Word?

If we use this code:

Sub FormatTableDemo()
Application.ScreenUpdating = False
Dim Tbl As Table
For Each Tbl In ActiveDocument.Tables
  With Tbl
    .AllowAutoFit = False
    .Rows.Alignment = wdAlignRowCenter
    .Range.Cells.VerticalAlignment = wdCellAlignVerticalTop
    .Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
    .Rows(1).Cells.VerticalAlignment = wdCellAlignVerticalCenter
    .Rows(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Columns(1).Width = CentimetersToPoints(0.95)
    .Columns(2).Width = CentimetersToPoints(0.95)
    .Columns(3).Width = CentimetersToPoints(7#)
    .Columns(4).Width = CentimetersToPoints(6#)
  End With
Next
Application.ScreenUpdating = True
End Sub

We only format all tables (not endnote tables)

CodePudding user response:

That's as simple as:

For Each Tbl In ActiveDocument.StoryRanges(wdEndnotesStory).Tables
  • Related