如何在 VBA 段落的第一行之前添加间距?
How to add spacing before first line of paragraph in VBA?
我正在尝试在自动生成的 word 文档中的一个段落之前添加间距。我只需要在该特定段落的第一行之前有间距。问题出在第一个空行之后的下一行。
With Wapp
With .Selection
.TypeParagraph
'Add line spacing
.ParagraphFormat.SpaceBefore = 0
.ParagraphFormat.SpaceAfter = 0
.TypeText St1
.TypeParagraph
.ParagraphFormat.SpaceBefore = 36
.BoldRun
'Centers text
.ParagraphFormat.Alignment = 1
.TypeText St2
.BoldRun
.ParagraphFormat.SpaceBefore = 0
.TypeText VBA.vbNewLine
.TypeText St3
.TypeText VBA.vbNewLine
.ParagraphFormat.Alignment = 1
End With
End With
交换了两行代码
.TypeText VBA.vbNewLine
和
.ParagraphFormat.SpaceBefore = 0
似乎将 .ParagraphFormat 放在 .TypeParagraph 或 VBA.vbNewLine 之后很重要,然后它开始按我想要的方式工作。
With Wapp
With .Selection
.TypeParagraph
'Add line spacing
.ParagraphFormat.SpaceBefore = 0
.ParagraphFormat.SpaceAfter = 0
.TypeText St1
.TypeParagraph
'Starts spacing
.ParagraphFormat.SpaceBefore = 6
.BoldRun
'Centers text
.ParagraphFormat.Alignment = 1
.TypeText St2
.BoldRun
.TypeText VBA.vbNewLine
'Ends spacing
.ParagraphFormat.SpaceBefore = 0
.TypeText St3
.TypeText VBA.vbNewLine
.ParagraphFormat.Alignment = 1
End With
End With
您可以使用以下行为当前段落创建 1 英寸(72 磅)的首行缩进:
.ParagraphFormat.FirstLineIndent = Application.InchesToPoints(1)
我正在尝试在自动生成的 word 文档中的一个段落之前添加间距。我只需要在该特定段落的第一行之前有间距。问题出在第一个空行之后的下一行。
With Wapp
With .Selection
.TypeParagraph
'Add line spacing
.ParagraphFormat.SpaceBefore = 0
.ParagraphFormat.SpaceAfter = 0
.TypeText St1
.TypeParagraph
.ParagraphFormat.SpaceBefore = 36
.BoldRun
'Centers text
.ParagraphFormat.Alignment = 1
.TypeText St2
.BoldRun
.ParagraphFormat.SpaceBefore = 0
.TypeText VBA.vbNewLine
.TypeText St3
.TypeText VBA.vbNewLine
.ParagraphFormat.Alignment = 1
End With
End With
交换了两行代码
.TypeText VBA.vbNewLine
和
.ParagraphFormat.SpaceBefore = 0
似乎将 .ParagraphFormat 放在 .TypeParagraph 或 VBA.vbNewLine 之后很重要,然后它开始按我想要的方式工作。
With Wapp
With .Selection
.TypeParagraph
'Add line spacing
.ParagraphFormat.SpaceBefore = 0
.ParagraphFormat.SpaceAfter = 0
.TypeText St1
.TypeParagraph
'Starts spacing
.ParagraphFormat.SpaceBefore = 6
.BoldRun
'Centers text
.ParagraphFormat.Alignment = 1
.TypeText St2
.BoldRun
.TypeText VBA.vbNewLine
'Ends spacing
.ParagraphFormat.SpaceBefore = 0
.TypeText St3
.TypeText VBA.vbNewLine
.ParagraphFormat.Alignment = 1
End With
End With
您可以使用以下行为当前段落创建 1 英寸(72 磅)的首行缩进:
.ParagraphFormat.FirstLineIndent = Application.InchesToPoints(1)