Solved

Renumber Word data

Posted on 2016-08-30
5
69 Views
Last Modified: 2016-09-01
Hi All,

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

e.g.  
click > [R001]
click > [R002]
etc.

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:
[R001]
[R003]
[R002]

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
0
Comment
Question by:theo kouwenhoven
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:xtermie
ID: 41777657
Can you please post a sample document?
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 41777801
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.

e.g.
[R001] > [R001]
[R025] > [R002]
[R002] > [R003]
etc
SampleDocument.doc
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 41778111
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") & "]"
        Loop
    End With

End Sub

Open in new window

~bp
0
 
LVL 16

Author Closing Comment

by:theo kouwenhoven
ID: 41779685
Great !!!!! thanks working fine :-)
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 41779885
Welcome.

~bp
0

Featured Post

Windows running painfully slow? Try these tips..

Stay away from Speed Up Computer Programs that do more harm than good.
Try these tips instead.
Step by step instructions in trouble shooting Windows Performance issues.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question