number generator within a document

S

Susan Glass

Hi,
I would like to be able to number paragraphs within a Word
document in a way that is based solely on the sequence of creation of
the paragraphs, and not on their location within the document. More
specifically, I am writing a Requirements document that can have
several hundred "Requirement" items/paragraphs in it. I want each
paragraph to be given a number when it is created that is unique
within the document, and then I want this number NEVER to change, even
if the paragraph is moved to a different location within the document.
This will allow us to make additons/deletions/other changes to the
document without changing our references to each paragraph.
I don't believe that any of the auto-numbering (bullets,
numbered, outline) tools in Word will work for this, because they
depend on location within the document and change as paragraphs with
the same style are added or removed. I started doing some research
and thought that maybe I could use a custom document property to store
the next number available, and then create a "Requirement" style that
somehow automatically entered the next number in the sequence and
incremented the custom property. I'm guessing that this is possible
to do with vba although I have not explored it yet.
I would like to know if people have any general or specific ideas
for how I can get my numbering to work, and/or if they think I am on
the right track with the document property idea or have suggestions on
implementing this idea. If there's a more appropriate usergroup I can
ask for information, I would like to know. I would appreciate any
help on this.

Thanks very much,
Susan
 
D

Dayo Mitchell

Hi Susan,

Why not just manually type the appropriate number as the paragraph is
created? Then you know Word will not change it.

DM
 
S

Susan Glass

Hi DM,
You asked:
Why not just manually type the appropriate number as the paragraph is
created? Then you know Word will not change it.

That was my first idea, since you could always keep a comment
somewhere in the document that contains the last number used.
However, my manager would really like the numbering to be automatic to
avoid any possibility of getting duplicate numbers. When you have a
document of 100 pages that is being worked on by several people, and
the numbered items are scattered throughout the doc out of order, it's
very possible that someone at some time will miscount or forget to
update the comment, and a duplicate number will be used.

Thanks,
Susan
 
D

Doug Robbins

I would create a template to use for creating such documents and in it,
create an AutoNew() macro that contains the following code which initiates a
variable within each document that is create from the template to a value of
1

Sub AutoNew()

ActiveDocument.Variables("Sequence").Value = 1

End Sub

Then have a second macro in the template that you run, any time that you
want to insert a number

Sub InsertNumber()

Selection.InsertBefore ActiveDocument.Variables("Sequence").Value & vbTab
ActiveDocument.Variables("Sequence").Value =
ActiveDocument.Variables("Sequence").Value + 1

End Sub

You could assign this second macro to a toolbar button or to the keyboard to
facilitate its use.

Every time that it is run, it will insert a number at the location of the
selection and increment the value of the variable stored in the document so
that the next time it is run, the next number is inserted.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top