Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

vba - What is a story?

In MS Word VBA, what is the unit of measure "Story" and where does it fit into the hierarchy of units in a Word document?

This reference only says that wdUnits.wdStory refers to "a story" which is not helpful. I couldn't find any other references that explain what I'm looking for.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is actually a more complicated question than most would think. In a Microsoft Word blog post stories are defined as:

"...distinct regions of content that make up a Word document and share properties and functionality. Put differently, behind the scenes, Word breaks all documents up into a collection of chunks with shared properties and functionality. Officially, these are called stories."

These chunks can be comments, endnotes, footnotes, footers, headers, etc.

Later on the blog post states:

"...all stories in a document utilize a common set of properties that determine the presentation of the contents within each story. These shared properties include font information, style definitions, numbering definitions, and document settings."

For more information, please see the full Microsoft blog post:

Behind the Curtain: Stories in Word

UPDATE

@WaiHaLee has brought to my attention that the Microsoft blog post I link to in my original answer is no longer available. Because of this, I will elaborate further on what a Story is in the Word Object Model.

As of this writing there are 17 types of Stories, as this screen capture from the Object Browser of the Word VBA IDE shows:

enter image description here

Each of these allows a specific region of content within a Word document to be affected programmatically, often via the StoryRanges collection.

Allen Wyatt has written a very good article entitled

Including Headers and Footers when Selecting All

wherein he explains some different methods for using StoryRanges. For example, one can update fields in only the Primary Footer area of a document:

ActiveDocument.StoryRanges(wdPrimaryFooterStory).Fields.Update

StoryRanges can also be used to search particular areas of a document as detailed in

Using a macro to replace text where ever it appears in a document

So in short, the StoryRanges collection allows a programmer to affect all or some of the unique parts of a Word Document. Each part is a Range enumerated as a StoryType. And each StoryType is what is meant as a Story within Word.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...