Solved

How to format autonum numbers to add several 0 before depending if they are one, two or three diggits.

Posted on 2014-11-26
8
44 Views
Last Modified: 2015-04-15
I am looking for a way to format auto numbers, so that they are always the same # of digits. Here is why: the first part of the number is supposed to be the date in a certain format, which works great, and the second part should be an auto-number which also works ok, but not how I need it. So how can I make this number: 201411261 look like this: 20141126001 as if it would always be a three digit number, (there is no case that the autonumber would ever be more than 3 digits)?
Thanks for your help
0
Comment
Question by:mvp1985
8 Comments
 
LVL 23

Expert Comment

by:Eirman
ID: 40466586
An imperfect possible workaround
.... start the auto numbering from 1001
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40466665
When the document is complete, you can run a VBA macro to replace the Autonum fields with formatted numbers. This code has been tested in Word 2007, Windows 7.
Sub FormatAutoNum()
    Dim fld As Field
    Dim n As Integer
    Dim rng As Range
    Dim f As Integer
    
    For f = ActiveDocument.Fields.Count To 1 Step -1
        Set fld = ActiveDocument.Fields(f)
        If fld.Type = wdFieldAutoNum Then
            Set rng = fld.Code
            fld.Unlink
            rng.Expand wdWord
            n = Val(rng.Text)
            rng.Text = Format(n, "000")
        End If
    Next f

End Sub

Open in new window

0
 

Author Comment

by:mvp1985
ID: 40466740
How can I start autonumbering at 1001 then?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40466801
If your version of Word supports it, you could use ListNum fields with the \s switch in the first one.
{LISTNUM \s 1000}
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:mvp1985
ID: 40466924
I just tried ListNum, but it does not add an additional number like AutoNum.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40467398
It isn't clear exactly what the difference is. The number seems to increment as expected.Image of field results
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40467410
I messed that up. Try again:

Image of codes:Field codes
Image of results:ListNumResults.PNG
0
 
LVL 21

Accepted Solution

by:
EricFletcher earned 500 total points
ID: 40468470
As in another of your questions (here), I suggest using field code switches and the SEQ field code. Consider the field codes and the results in the screen captures below:
Adding a 3-digit sequence to a date-based valueIn the above, I've set a bookmark named “fcDate” (shown within the [ ] bookmark indicators made visible onscreen by File Options > Advanced > Show document content, Show bookmarks).

On the 2nd line, I've set up a sequence named “Suffix” and set its initial value to 0. The \h switch hides the result (as can be seen in the corresponding result screen capture).

The other lines use the REFerence field code to pull the value of the named bookmark and format it as a date without any separators, but then also adds a SEQ field to insert the sequence’s incrementing value formatted with leading zeros.

Other field codes can use a similar approach, depending on how you can reference your source date values. MailMerge is perhaps the best option if the values are (or can be) in a list. Select all and use Shift-Ctrl-F9 to convert the calculated results to text.

(As noted in the other question, my screen captures above show the result of turning on field code visibility with File Options > Advanced > Show document content, Field shading=Always.)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now