Sequential counters

S

Sidd

Hi experts,

I would like to add tags to a document with the following
requirements:

1. The tag has two counters
2. The value of one counter is typical, i.e. it depends
on its position within the document and hence can get re-
computed if content is moved around and its relative
position changes.
3. The value of the other counter within the tag is
temporally sequential - strictly based on when I added the
tag. It should not change based on its position within
the document - it is a running counter.

Thus if I move the tag around, the first counter will
readjust its value, while the second counter will have a
fixed value.

Also, if I delete a tag, then there may be "holes" in the
sequence of values of the second counter, whereas the
first counter will have happily readjusted its values
through the document.

Can I do this using any standard fields - SEQ, LISTNUM
etc. or do I have to do some deft VBA programming? --
Code snippets welcome in this case.

Thanks much

-Sidd

Example below:

PRD:1 TPRD:1 The case shall be blue.
PRD:2 TPRD:2 The handles shall be white.
.....

After adding another tagged statement you would have.

PRD:1 T:pRD:1 The case shall be blue.
PRD:2 T:pRD:45 The case shall be scratch resistant.
PRD:3 T:pRD:2 The handles shall be white.
.....

45 (as example here) reflects the number of all tags
intended or inadvertent that have thus far been entered
into the document, some of which may have been deleted, in
this case 45.
 
G

Greg

Sidd,

Try this:

1. Enter the following field
{ Quote PRD:" "{SEQ TagRunning}" "PRD:" "}
2. Toggle it, select it, and create an AutoText entry named "DocTags"

Use this pair of macros to reset the total counter and insert the tags:

Option Explicit
Dim oVar As Variable
Sub Reset()
For Each oVar In ActiveDocument.Variables
oVar.Delete
Next
ActiveDocument.Variables("TagTotal").Value = 0
End Sub
Sub AddTag()
Set oVar = ActiveDocument.Variables("TagTotal")
Dim myString As String
oVar = oVar + 1
myString = oVar
NormalTemplate.AutoTextEntries("DocTags").Insert
Where:=Selection.Range
Selection.InsertAfter (myString)
Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Fields.Update
End Sub
 
S

Sidd

Greg,

Thanks for the suggestion. I tried it out. VBA is
failing highlighting "Insert" in the statement

NormalTemplate.AutoTextEntries("DocTags").Insert

The error message is Compile error: Argument not optional

Also the line
Where:=Selection.Range is highlighted in Red in VBA

Any clues what is happening? Also, are the outermost curly
braces in your field plain text OR are they too field
delimiters. Thus is it a field contained within a field?
OR curly delimited tesxt containing one field

Thanks,

-Sidd
 
G

Greg

Sidd,

The line Where:=Selection ..... should be brought up to the previous
line

Yes this is a SEQ field nested in a Quote field. You will need two
pairs of field delimiters.
 

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