【发布时间】:2019-10-31 11:03:55
【问题描述】:
我有一个函数可以为书中的标题设置样式。我正在尝试将不同的样式应用于文档的其他部分,但无法完全正常工作。
所以有3种样式:
- 章节标题
- 章节标题后的第一行文本到下一个换行符 (^p)
- 第一行之后的所有内容,直到下一个分页符 (^m)
我确定我使用通配符向其他数组声明 - 但在逻辑上遇到了困难,并且在通配符 = true 时遇到了问题。
如果有人也碰巧有任何关于如何设置自己的样式的资源,然后将它们声明到每个部分(请参阅代码中的替换样式以了解我想要做什么 - “标题 1,章节标题” - 我可以在宏中定义它吗?),我真的很感激!
有关章节功能,请参见下面的代码。
Private Function iiiChapterHeadings()
Dim Chapters As Variant, Chapter
Chapters = Array("Chapter One", "Chapter Two", "Chapter Three")
For Each Chapter In Chapters
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles( _
"Heading 1,Chapter Heading")
With Selection.Find
.Text = Chapter
.Replacement.Text = "^m" & Chapter & "^p^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Function
文档示例!!!!
Chapter One^p
^p
This first line of text will have a style set to it so there's no indentation, the first letter of the sentence is a capital letter and it applies to everything up to the next line break.^p
Everything after the line break above has a different style set to it.^p
All of this will have that style up until the next page break.^p
As will this line.^p
And this etc. ^p
^m
Chapter Two^p
^p
【问题讨论】:
标签: arrays vba ms-word find variant