共用方式為


StoryRanges 物件 (Word)

一群 範圍 代表文件中的本文的物件。

註解

使用 StoryRanges 屬性可傳回整個 StoryRanges 集合。 下列範例會移除手動字元格式中使用中文件的主要文字本文以外的所有本文中的文字。

For Each aStory In ActiveDocument.StoryRanges 
 If aStory.StoryType <> wdMainTextStory Then aStory.Font.Reset 
Next aStory

Add 方法不適用於尋找整個 StoryRanges 集合。 Stories StoryRanges 集合中的數目是有限的。

使用 StoryRanges (Index) ,其中 Index 是 WdStoryType 常 數,可傳回單一本文作為 Range 物件。 下列範例會將文字加入主要標頭本文,然後顯示 [文字。

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

方法

名稱
項目

屬性

名稱
Application
數目
Creator
Parent

另請參閱

Word 物件模型參考資料

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應