?、賹⒏袷綉?yīng)用于選定內(nèi)容
下列示例使用Selection屬性將字符和段落格式應(yīng)用于選定文本。使用Font屬性獲得字體格式的屬性和方法,使用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
?、趯⒏袷綉?yīng)用于某一區(qū)域
下列示例定義了一個(gè)Range對象,它引用了活動文檔的前三個(gè)段落。通過應(yīng)用Font 和ParagraphFormat對象的屬性來設(shè)置 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
?、鄄迦胛淖植?yīng)用字符和段落格式
下列示例在當(dāng)前文檔的上部添加單詞 Title。第一段居中對齊,并在該段落之后添加半英寸的間距。將單詞 Title 的格式設(shè)為 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 磅和無之間切換段前間距
下列示例切換選定內(nèi)容中第一段的段前間距。宏將獲取當(dāng)前段前間距的值,如果該值為 12 磅,則刪除段前間距格式(將SpaceBefore屬性設(shè)為零)。如果段前間距的值為除 12 外的其它數(shù)值,則將 SpaceBefore屬性設(shè)為 12 磅。
Sub ToggleParagraphSpace()
With Selection.Paragraphs(1)
If .SpaceBefore <> 0 Then
.SpaceBefore = 0
Else
.SpaceBefore = 6
End If
End With
End Sub
?、萸袚Q加粗格式
下列示例切換選定文本的加粗格式。
Sub ToggleBold()
Selection.Font.Bold = wdToggle
End Sub
?、迣⒆筮吘嘣黾?0.5 英寸
下列示例將左邊距和右邊距增加 0.5 英寸。PageSetup對象包含文檔的所有的頁面設(shè)置屬性(左邊距、下邊距、紙張大小等)。LeftMargin屬性用于返回和設(shè)置左邊距設(shè)置。RightMargin屬性用于返回和設(shè)置右邊距設(shè)置。
Sub FormatMargins()
With ActiveDocument.PageSetup
.LeftMargin = .LeftMargin + InchesToPoints(0.5)
.RightMargin = .RightMargin + InchesToPoints(0.5)
End With
End Sub
新聞熱點(diǎn)
疑難解答
圖片精選