Share via

Macro to insert specifically formatted table

Anonymous
2010-09-23T15:16:35+00:00

I recorded a macro to insert a specifically formatted table. The table has 1 column, and two rows. The first row is shaded black, the second row is unshaded. Both rows are bold text and should only be 12 points in height (default font size for the document).  The table inserts fine if the paragraph settings are spaced 0 pts both before and after.  However if the paragraphs have any spacing applied, the inserted table takes that setting into account.  I tried recording the macro to include setting the paragraph spacing before inserting the table, but this seems to have done nothing.  Can anyone suggest a resolution for this?  Macro code follows.

Thanks,

Karl

Sub InsertSlideDialog()

'

' InsertSlideDialog Macro

' This inserts a properly formatted slide dialog box.

'

    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _

        1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _

        wdAutoFitFixed

    With Selection.Tables(1)

        If .Style <> "Table Grid" Then

            .Style = "Table Grid"

        End If

        .ApplyStyleHeadingRows = True

        .ApplyStyleLastRow = False

        .ApplyStyleFirstColumn = True

        .ApplyStyleLastColumn = False

        .ApplyStyleRowBands = True

        .ApplyStyleColumnBands = False

    End With

    With Selection.Font

        .Name = "Times New Roman Bold"

        .Size = 12

        .Bold = True

        .Italic = False

        .Underline = wdUnderlineNone

        .UnderlineColor = wdColorAutomatic

        .StrikeThrough = False

        .DoubleStrikeThrough = False

        .Outline = False

        .Emboss = False

        .Shadow = False

        .Hidden = False

        .SmallCaps = False

        .AllCaps = False

        .Color = wdColorAutomatic

        .Engrave = False

        .Superscript = False

        .Subscript = False

        .Spacing = 0

        .Scaling = 100

        .Position = 0

        .Kerning = 0

        .Animation = wdAnimationNone

    End With

    Selection.Shading.Texture = wdTextureNone

    Selection.Shading.ForegroundPatternColor = wdColorAutomatic

    Selection.Shading.BackgroundPatternColor = -587137025

    Selection.Font.Color = -603914241

    Selection.TypeText Text:="Slide"

End Sub

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-09-23T17:14:13+00:00

Hi,

I think the following accomplishes what you're after:

Dim oTbl As Table

Set oTbl = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=2, NumColumns:= _

        1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _

        wdAutoFitFixed)

    With oTbl

        If .Style <> "Table Grid" Then

            .Style = "Table Grid"

        End If

        .ApplyStyleHeadingRows = True

        .ApplyStyleLastRow = False

        .ApplyStyleFirstColumn = True

        .ApplyStyleLastColumn = False

        .ApplyStyleRowBands = True

        .ApplyStyleColumnBands = False

        With .Range

            '''sets the before/after spacing for the entire table

            .ParagraphFormat.SpaceBefore = InchesToPoints(0)

            .ParagraphFormat.SpaceAfter = InchesToPoints(0)

            With .Font

                .Name = "Times New Roman Bold"

                .Size = 12

                .Bold = True

                .Italic = False

                .Underline = wdUnderlineNone

                .UnderlineColor = wdColorAutomatic

                .StrikeThrough = False

                .DoubleStrikeThrough = False

                .Outline = False

                .Emboss = False

                .Shadow = False

                .Hidden = False

                .SmallCaps = False

                .AllCaps = False

                .Color = wdColorAutomatic

                .Engrave = False

                .Superscript = False

                .Subscript = False

                .Spacing = 0

                .Scaling = 100

                .Position = 0

                .Kerning = 0

                .Animation = wdAnimationNone

            End With

        End With

        With .Range.Cells(1)

            .Shading.ForegroundPatternColor = wdColorAutomatic

            .Shading.BackgroundPatternColor = -587137025

            .Range.Font.Color = -603914241

            .Range.text = "Slide"

        End With

    End With

HTH,

Dave

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2010-09-23T18:11:13+00:00

    Hi Dave,

    That absolutely did the trick!  Thanks much!

    Karl

    Was this answer helpful?

    0 comments No comments