Documents (Document)![]() ![]() ![]() |
由 Range 对象组成的集合,该集合代表文档中的文字部分。
可使用 StoryRanges 属性返回 StoryRanges 集合。下例在活动文档所有文字部分中删除与主文本部分不同的自定义字符格式。
For Each aStory In ActiveDocument.StoryRanges
If aStory.StoryType <> wdMainTextStory Then aStory.Font.Reset
Next aStory
Add 方法在 StoryRanges 集合中无效。StoryRanges 集合中所包含的文字部分的数量是有限的。
可使用 StoryRanges(index) 返回单个部分(作为一个 Range 对象),其中 index 为一个 wdStoryType 常量。下例在页眉部分中添加并显示文本。
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range _
.Text = "Header text"
MsgBox ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Text
下例将活动文档脚注部分中的文本复制到一个新文档。
If ActiveDocument.Footnotes.Count >= 1 Then
ActiveDocument.StoryRanges(wdFootnotesStory).Copy
Documents.Add.Content.Paste
End If
试图返回一个指定文档中无效的部分时会出错。下例确定脚注部分在活动文档中是否有效。
On Error GoTo errhandler
Set MyRange = ActiveDocument.StoryRanges(wdFootnotesStory)
errhandler:
If Err = 5941 Then MsgBox "The footnotes story is not available."
可使用 NextStoryRange 属性在文档各部分间循环。下例在活动文档的各部分中寻找“Microsoft Word”,如找到则将其设置为斜体格式。
For Each myStoryRange In ActiveDocument.StoryRanges
myStoryRange.Find.Execute _
FindText:="Microsoft Word", Forward:=True
While myStoryRange.Find.Found
myStoryRange.Italic = True
myStoryRange.Find.Execute _
FindText:="Microsoft Word", Forward:=True
Wend
While Not (myStoryRange.NextStoryRange Is Nothing)
Set myStoryRange = myStoryRange.NextStoryRange
myStoryRange.Find.Execute _
FindText:="Microsoft Word", Forward:=True
While myStoryRange.Find.Found
myStoryRange.Italic = True
myStoryRange.Find.Execute _
FindText:="Microsoft Word", Forward:=True
Wend
Wend
Next myStoryRange