vba - 如何在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
推荐阅读
- ios - 我想在 getPicture - ionic ios 的警报中更改“您的使用信息”的文本
- npm - 如何为现有的 Lerna mono-repo 生成每个包的 package-lock.json
- react-native - ReactNative:顶部的应用程序名称
- google-sheets - “间接”Excel 功能无法在 Google 表格上按预期工作
- gitlab - 有人能够使用 terraform 为 repo 启用现有的部署密钥吗?
- oracle-apex-5.1 - Oracle APEX 区域宽度
- javascript - 如何访问此类属性?
- php - 如何使用 gmail API 发送大附件
- image - 黑白图像的 1 位 RLE(运行长度编码)
- r - 递归 R 包安装失败