• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 89
  • Last Modified:

Renumber Word data

Hi All,

I have a function to insert reference numbers into a word document with a mouse click:

click > [R001]
click > [R002]

While maintaining this document, it can hapen that the function is used to insert new numbers

click > [R003]

But the result after that could be:

I'm looking for a function, that will search for the [Rxxx] format and renumber this in the the whole document, without changing other stuff.

I don't write VBA (oke a little) so please keep it simple
  • 2
  • 2
1 Solution
Can you please post a sample document?
MurpheyApplication ConsultantAuthor Commented:
Hi xtermie,

I was not allowed to attach the .docm file so I renamed it to .doc.
In the example there are some rows, but also the VB source that is used to insert the reference numbers.

It would be nice if it can write some logging to a TXT file during the rename actions.

[R001] > [R001]
[R025] > [R002]
[R002] > [R003]
Bill PrewCommented:
Give this VBA subroutine a try, seemed to do the job here.

Sub SequenceNumbers()
    Dim rng As Range
    Dim i As Integer

    ' Initialize new sequence values
    i = 0
    ' Search entire document
    Set rng = ActiveDocument.Range
    ' Use Word FIND methond to do a simple regular expression search
    With rng.Find
        ' Look for our sequence tags in format [Rnnn]
        .Text = "(\[R[0-9]{3}\])"
        .MatchWildcards = True
        ' Loop finding each matching tag
        Do While .Execute()
            ' Increment new sequence number and update this tag
            i = i + 1
            rng.Text = "[R" & Format(i, "000") & "]"
    End With

End Sub

Open in new window

MurpheyApplication ConsultantAuthor Commented:
Great !!!!! thanks working fine :-)
Bill PrewCommented:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now