-3

I want to create a Word macro that can do the following task at a single click. Please help me. I have a large document that's a trouble for me.

The task includes a table formatting such as

table width 11 cm,
left aligned,
font TNR 10,
border black,
indent from left is zero.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
rairkz
  • 3
  • 1
  • 7
  • OK. Go ahead. Use the Word macro recorder, and format the table (create a small one in another document). When you're done, stop recording and... Voila! You have a macro! Copy it into your real document, make any changes to work with your actual table, and you're all set. – Ken White Jan 21 '17 at 03:36

1 Answers1

0

I got the macro code.... Thanks..

Sub Macro1()

With Selection.tables(1)
    .Rows.HeightRule = wdRowHeightAuto
    .PreferredWidthType = wdPreferredWidthPoints
    .PreferredWidth = CentimetersToPoints(11)
End With


With Selection.Borders(wdBorderTop)
    .LineStyle = Options.DefaultBorderLineStyle
    .LineWidth = Options.DefaultBorderLineWidth
    .Color = Options.DefaultBorderColor

End With
With Selection.Borders(wdBorderLeft)
    .LineStyle = Options.DefaultBorderLineStyle
    .LineWidth = Options.DefaultBorderLineWidth
    .Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderBottom)
    .LineStyle = Options.DefaultBorderLineStyle
    .LineWidth = Options.DefaultBorderLineWidth
    .Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderRight)
    .LineStyle = Options.DefaultBorderLineStyle
    .LineWidth = Options.DefaultBorderLineWidth
    .Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderVertical)
    .LineStyle = Options.DefaultBorderLineStyle
    .LineWidth = Options.DefaultBorderLineWidth
    .Color = Options.DefaultBorderColor
End With
    With Selection.Borders(wdBorderHorizontal)
    .LineStyle = Options.DefaultBorderLineStyle
    .LineWidth = Options.DefaultBorderLineWidth
    .Color = Options.DefaultBorderColor
End With
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
With Selection.ParagraphFormat
    .LeftIndent = CentimetersToPoints(0)
    .RightIndent = CentimetersToPoints(0)
    .SpaceBefore = 0
    .SpaceBeforeAuto = False
    .SpaceAfter = 0
    .SpaceAfterAuto = False
    .LineSpacingRule = wdLineSpaceSingle
    .Alignment = wdAlignParagraphLeft
    .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
With Selection.ParagraphFormat
    .LeftIndent = CentimetersToPoints(0)
    .RightIndent = CentimetersToPoints(0)
    .SpaceBefore = 0
    .SpaceBeforeAuto = False
    .SpaceAfter = 0
    .SpaceAfterAuto = False
    .LineSpacingRule = wdLineSpaceSingle
    .Alignment = wdAlignParagraphLeft
    .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

    With Selection.tables(1).Rows
    .Alignment = wdAlignRowLeft
    .AllowBreakAcrossPages = True
    .SetLeftIndent LeftIndent:=CentimetersToPoints(0), RulerStyle:= _
        wdAdjustNone
End With

End Sub

rairkz
  • 3
  • 1
  • 7