-
Notifications
You must be signed in to change notification settings - Fork 0
/
FmtTbls.bas
78 lines (67 loc) · 2.82 KB
/
FmtTbls.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Attribute VB_Name = "NewMacros"
Option Explicit
Sub FmtTbls()
'*******************************************************************************
'Fixes and standardizes formatting of all tables in the active document:
' - Sets default borders.
' - Horizontally and vertically center aligns values.
' - Sets uniform row height.
' - Center aligns table.
' - AutoFits column widths.
' - Disallows the table from spanning multiple pages.
' - Bolds the first row (header row).
' - Changes red text to black highlighted text.
' - Sets the font.
'*******************************************************************************
'Iteration variables
Dim tbl As Table
Dim varBorder As Variant 'Type of table border
Dim cell As cell
'Iterate over all tables in the active document
For Each tbl In ActiveDocument.Tables
tbl.Select
With Selection
'Default borders
For Each varBorder In Array(wdBorderTop, wdBorderLeft, wdBorderBottom, wdBorderRight, wdBorderHorizontal, wdBorderVertical)
With .Borders(varBorder)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Next varBorder
'Center align table and values
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Rows.Alignment = wdAlignRowCenter
'Row height
.Rows.HeightRule = wdRowHeightExactly
.Rows.Height = InchesToPoints(0.25)
'Center align values
.Cells.VerticalAlignment = wdCellAlignVerticalCenter
With .Tables(1)
'AutoFit columns
.AutoFitBehavior (wdAutoFitContent)
'Cell padding
.TopPadding = InchesToPoints(0)
.BottomPadding = InchesToPoints(0)
.LeftPadding = InchesToPoints(0.08)
.RightPadding = InchesToPoints(0.08)
'Misc. cell formatting
.Spacing = 0
.AllowPageBreaks = False
.AllowAutoFit = True
End With
For Each cell In .Cells
'Bold first row
If cell.RowIndex = 1 Then cell.Range.Font.Bold = 1
'Change red text to highlighted
If cell.Range.Font.TextColor = wdColorRed Then cell.Range.HighlightColorIndex = wdYellow
Next cell
'Font is black, TNR, size 12
With .Font
.TextColor = wdColorBlack
.Name = "Times New Roman"
.Size = 12
End With
End With
Next tbl
End Sub