http://www.pptjcw.com

word文档编辑教程:vba设置word文档的格式

    ①将格式应用于选定内容

    下列示例使用Selection属性将字符和段落格式应用于选定文本。使用Font属性获得字体格式的属性和方法,pdf怎么转换成wordWORD上下页,使用ParagraphFormat属性获得段落格式的属性和方法。

    Sub FormatSelection()

    With Selection.Font

    .Name = "Times New Roman"

    .Size = 14

    .AllCaps = True

    End With

    With Selection.ParagraphFormat

    .LeftIndent = InchesToPoints(0.5)

    .Space1

    End With

    End Sub

    ②将格式应用于某一区域

    下列示例定义了一个Range对象,它引用了活动文档的前三个段落。通过应用Font 和ParagraphFormat对象的属性来设置 Range对象的格式。

    Sub FormatRange()

    Dim rngFormat As Range

    Set rngFormat = ActiveDocument.Range( _

    Start:=ActiveDocument.Paragraphs(1).Range.Start, _

    End:=ActiveDocument.Paragraphs(3).Range.End)

    With rngFormat

    .Font.Name = "Arial"

    .ParagraphFormat.Alignment = wdAlignParagraphJustify

    End With

    End Sub

    ③插入文字并应用字符和段落格式

    下列示例在当前文档的上部添加单词 Title。第一段居中对齐,word多出来一页空白页删不掉,并在该段落之后添加半英寸的间距。将单词 Title 的格式设为 24 磅 Arial 字体。

    Sub InsertFormatText()

    Dim rngFormat As Range

    Set rngFormat = ActiveDocument.Range(Start:=0, End:=0)

    With rngFormat

    .InsertAfter Text:="Title"

    .InsertParagraphAfter

    With .Font

    .Name = "Tahoma"

    .Size = 24

    .Bold = True

    End With

    End With

    With ActiveDocument.Paragraphs(1)

    .Alignment = wdAlignParagraphCenter

    .SpaceAfter = InchesToPoints(0.5)

    End With

    End Sub

    ④在 12 磅和无之间切换段前间距

    下列示例切换选定内容中第一段的段前间距。宏将获取当前段前间距的值,如果该值为 12 磅,则删除段前间距格式(将SpaceBefore属性设为零)。如果段前间距的值为除 12 外的其它数值,则将 SpaceBefore属性设为 12 磅。

    Sub ToggleParagraphSpace()

    With Selection.Paragraphs(1)

    If .SpaceBefore <> 0 Then

    .SpaceBefore = 0

    Else

    .SpaceBefore = 6

    End If

    End With

    End Sub

    ⑤切换加粗格式

    下列示例切换选定文本的加粗格式。

    Sub ToggleBold()

    Selection.Font.Bold = wdToggle

    End Sub

    ⑥将左边距增加 0.5 英寸

    下列示例将左边距和右边距增加 0.5 英寸。PageSetup对象包含文档的所有的页面设置属性(左边距、下边距、纸张大小等)。LeftMargin属性用于返回和设置左边距设置。RightMargin属性用于返回和设置右边距设置。

    Sub FormatMargins()

    With ActiveDocument.PageSetup

    .LeftMargin = .LeftMargin + InchesToPoints(0.5)

    .RightMargin = .RightMargin + InchesToPoints(0.5)

    提示:如果您觉得本文不错,请点击分享给您的好友!谢谢

    上一篇:word文档转成ppt教程:Word竖排文本框的文字居中对齐方式的设置 下一篇:word教程基础入门:如何让WORD的宏随文档的打开自动运行

    郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

相关文章阅读