sort out your tables

My colleague Duane Arl was very frustrated that his tables kept appearing with the writing above the middle of the line, even though he set his table to be centre justified:

‘Why is everything floating up near the top?’ he would screech. ‘Well, Duane, it’s because in Paragraph your tables have a line spacing of 1.5 – if you set the line spacing to 1 line you will have your data in the middle:

‘But my whole document is spaced at 1.5 lines – do I have to go through and change each table individually?’ ‘No, Duane,’ I replied, ‘Just run the macro below over your document – the whole thing will stay at a spacing of 1.5 but your tables will be spaced at 1 line and all your data will be in the middle.’

Dim J As Integer
    Dim iTableNum As Integer
    Dim oTbl As Table

    Selection.Bookmarks.Add ("TempBM")
    For J = 1 To ActiveDocument.Tables.Count
        Set oTbl = ActiveDocument.Tables(J)
        oTbl.Select
        If Selection.Bookmarks.Exists("TempBM") Then
            iTableNum = J
            Exit For
        End If
        
      With Selection.ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphJustify
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .CollapsedByDefault = False
    End With
        
    Next J
    ActiveDocument.Bookmarks("TempBM").Select
    ActiveDocument.Bookmarks("TempBM").Delete

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: