StoryRanges オブジェクト (Word)

範囲 のコレクション ドキュメント内のストーリーを表すオブジェクト。

注釈

StoryRanges コレクションを取得するのにには、 StoryRanges プロパティを使用します。 次の使用例は、作業中の文書でメイン テキスト ストーリー以外のすべてのストーリー内のテキストの書式設定の手動の文字を削除します。

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

StoryRanges コレクションの Add メソッドが得られません。 StoryRanges コレクションのストーリーの数は有限です。

単一のストーリーをRange オブジェクトとして返すには、StoryRanges (Index) を使用します。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

メソッド

名前
アイテム

プロパティ

名前
アプリケーション
Count
Creator
Parent

関連項目

Word オブジェクト モデル リファレンス

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。