下面的VBA代碼功能,第一步,word當前文檔的上面添加文字dzwebs文字。然後,又設置第一段居中對齊,並在該段落之後添加半英寸的間距。將dzwebs的格式設為36磅,隸書字體。
Dim rngFormat As Range
Set rngFormat = ActiveDocument.Range(Start:=0, End:=0)
With rngFormat
.InsertAfter Text:="dzwebs"
.InsertParagraphAfter
With .Font
.Name = "隸書"
.Size = 36
.Bold = True
End With
End With
With ActiveDocument.Paragraphs(1)
.Alignment = wdAlignParagraphCenter
.SpaceAfter = InchesToPoints(0.5)
End With
部分代碼解釋:
Dim rngFormat As Range 定義變量
Set rngFormat = ActiveDocument.Range(Start:=0, End:=0) 設置rngFormat變量的位置,位於文檔的最上面
With rngFormat
裡面的代碼功能是設置字體字號等屬性
End With
With ActiveDocument.Paragraphs(1)
.Alignment = wdAlignParagraphCenter
.SpaceAfter = InchesToPoints(0.5)
End With
該代碼代碼功能是添加段後距離為0.5英寸