【问题标题】:I want to create a Word macro for table formatting我想为表格格式创建一个 Word 宏
【发布时间】:2017-01-21 03:22:16
【问题描述】:

我想创建一个 Word 宏,只需单击一下即可完成以下任务。 请帮我。 我有一个大文件,这对我来说很麻烦。

任务包括表格格式,例如

桌宽 11 厘米,
左对齐,
字体 TNR 10,
边框黑色,
左缩进为零。

【问题讨论】:

  • 好的。前进。使用 Word 宏记录器,并格式化表格(在另一个文档中创建一个小表格)。完成后,停止录制,然后……瞧!你有一个宏!将其复制到您的真实文档中,进行任何更改以使用您的实际表格,然后一切就绪。

标签: vba ms-word format tabular


【解决方案1】:

我得到了宏代码.... 谢谢..

子宏1()

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

结束子

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2019-02-10
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多