We help IT Professionals succeed at work.

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

mvp1985
mvp1985 asked
on
204 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
Comment
Watch Question

EirmanChief Operations Manager
CERTIFIED EXPERT

Commented:
An imperfect possible workaround
.... start the auto numbering from 1001
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
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

Author

Commented:
How can I start autonumbering at 1001 then?
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
If your version of Word supports it, you could use ListNum fields with the \s switch in the first one.
{LISTNUM \s 1000}

Author

Commented:
I just tried ListNum, but it does not add an additional number like AutoNum.
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
It isn't clear exactly what the difference is. The number seems to increment as expected.Image of field results
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
I messed that up. Try again:

Image of codes:Field codes
Image of results:ListNumResults.PNG
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.