Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Inserting a calculated number (W97)

    I'm creating a template that I want to include the following functionality:

    I want to insert an ID number at the end of a paragraph. (i)
    The ID number must increase by 1 each time (i+1)
    The first ID number for a given document must start at 1
    The last ID number used must be stored within the document, so that future editing of the document may continue with the last ID number issued.

    I've started creating something , but don't know where to go with it. (it's the whole variable part that I'm still weak on.... )
    I don't know where to store the 'last used id number', nor how to increment.


    <pre>Sub InsertIDNumberManually()

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting a calculated number (W97)

    One way is to use a Document Variable to hold the ID number.

    The trick with docvars is this: you can insert references to docvars
    (in order to display the value of the docvar) via Insert | Fields -- and via
    code; but you can assign values to docvars only via code.

    So, you end up creating a handy set of docvar functions and subs:

    DocVarAssign
    DocVarExists
    DocVarDelete, etc.

    They are about as complex as this:
    Function DocVarDelete(DocVar As String) As String
    On Error Resume Next
    ActiveDocument.Variables(DocVar).Delete
    Err.Clear
    End Function

    and this:
    Sub DocVarAssign(DocVar As String, ByVal DocValue As Variant)
    On Error Resume Next
    With ActiveDocument
    .Variables(DocVar).Delete
    .Variables.Add Name:=DocVar, Value:=DocValue
    End With
    Err.Clear
    End Sub

    That's a start anyway.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Inserting a calculated number (W97)

    Is the ID number to be fixed to each paragraph. For instance, is the number stream always sequential if I add a new paragraph (or remove some) early in the document does it get the next available number or will the subsequent paragraphs renumber to make way for it.

    If they renumber then I would use a seq field instead of a hard coded number.

    Is every paragraph numbered? If so you could use a Range.Paragraphs.Count to easily work out the next number available for use.

    If the numbers are fixed, can be applied out of order, and dont apply to every paragraph then I would use a macro solution with a bookmark.
    The macro would search for the bookmark - read its contents and then increment this number by one and insert this next number at the required location with the same bookmark name (this removes the previous location). Finding the last added number is then as simple as finding the bookmark.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Inserting a calculated number (W97)

    This number is an ID number for requirement traceability. It will be attached to the end of many paragraphs perminantly, but only upon assignment (Tagging each requirement). I want to attach the code to a toolbar button "Issue ID #" When the press the button, the macro assigns the next available ID number to the end of the paragraph (assigns a unique number to the requirement).

  5. #5
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Inserting a calculated number (W97)

    Can I store this variable in the Doc Object/Document_Open?
    I tried creatint a lil workflow diagram.....

    1. <pre>Dim IDNUM
    i=0
    IDNUM = i+1
    (Stored in Document_Open) ???
    </pre>



    2. Code that I entered above (to execute action, activated by a toolbar button)
    3.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •