Increment a sequential number for each document created

Solved
tontonzunny -  
 tontonzunny -
Hello,
I am looking to increment a chronological number with each document creation based on this template.
I found this

Create a new file and save it as a template, under the name "order form," for example.

Create a macro named "AutoNew":

This macro stores in an auto-insertion named "number" the one assigned to the last document based on the order form template.

To initialize this auto-insertion, enter in the document the number that will be assigned to the first document (minus 1). Select this number and choose the command:

Word 2000 to 2003: Insert, AutoText-AutoText.
Word 2007 to 2010: Insert tab; Text group, Quick Parts, AutoText, Save Selection to AutoText Gallery

- Type the name of the insertion: "number".
- In the "Look in" list, select order form.dot(m) to save it in the template. Click Add (2000 to 2003) or OK (2007 to 2010).
- Clear the number that was entered, save the template and close it.

To start a new order form, choose File-New and double-click on the icon of the Order Form template. The numbering will be done and the document is automatically saved (be careful to be in the folder where the order form should be stored)

Macro to copy by Alt + F11, paste into ThisDocument, File, Close and return to Word

Sub AutoNew ()
num = ActiveDocument.AttachedTemplate.AutoTextEntries("number").Value
num = num + 1
ActiveDocument.AttachedTemplate.AutoTextEntries("number").Value = num
num = Right("0000" & num, 4)
Selection.TypeText Text:="Order Form No " & num
SendKeys "o"
ActiveDocument.SaveAs FileName:="Order Form " & num & ".doc"

But after several attempts, nothing works, an error message appears, I think it's because I'm working on WORD 2010

Can someone help me?
Thanks

Configuration: Windows Vista / Firefox 37.0

5 answers

C-Claire Posted messages 4562 Registration date   Status Member Last intervention   2 250
 
Hello,

"I found this": it would be good to indicate the source.
In this case, it is the site of m@rina, very active here, and more specifically the following page:
https://www.faqword.com/index.php/word/faq-word/mise-en-forme/466-serait-il-possible-a-partir-dun-modele-word-dincrementer-un-numero-chronologique-a-chaque-creation-de-document-base-sur-ce-modele

I haven't tested it, but I would be surprised if it doesn't work since v2010 is mentioned.

But to move forward, it would be interesting for you to indicate the content of the error message.

--
C-Claire
1
tontonzunny Posted messages 6 Status Member
 
Hello
that's exactly what I found
I can't get it to work... maybe it's my fault, so I'm asking
the message says the required collection member does not exist
thank you for your reply
0
tontonzunny Posted messages 6 Status Member
 
I have this appearing after various actions

ActiveDocument.AttachedTemplate.AutoTextEntries("number").Value = Num

just before a window opens saying debug error...
0
C-Claire Posted messages 4562 Registration date   Status Member Last intervention   2 250
 
Have you successfully created the automatic insertion named "numéro" without the quotes but with the accent?

C-Claire
0
tontonzunny
 
I just did it again, still the same problem
a window with
execution error 5825
The object has been deleted.
0
tontonzunny
 
this error arises from the fact that I am deleting the number as indicated...
actually this is the error
" required collection member does not exist
thank you for your response"
0
tontonzunny
 
"I didn't understand that

"choose File-New and double-click on the Purchase Order template icon. The numbering is done and the document is automatically saved (be careful to be in the folder where the purchase order should be stored)""
0
C-Claire Posted messages 4562 Registration date   Status Member Last intervention   2 250 > tontonzunny
 
If you usually open your documents from Windows Explorer, you can replace File-New with a double-click on your .dotm template.
In both cases, this will open a copy of the template and the macro will run.

The command
ActiveDocument.SaveAs FileName:="Order form" & num & ".doc"
automatically saves your document as "Order form" followed by the number. You can change .doc to .docx for Word 2010.
But you can also delete this line if you prefer to save the document yourself in the folder you want.

C-Claire
0
tontonzunny
 
hello
well, I've tried all possible manipulations but I can't do it. I'm probably not putting the macro in the right place or maybe I'm copying it wrong.
Anyway, I've given up, I'll go through Excel and include a chart.
I don't have time to explain it right now but I will, basically:
I've created a button that increments a number by pressing it (+1 each time), I've used several cells to concatenate them into one number, and I've created a button to reset it whenever I want.
I'll explain better later...
See you soon and thanks for your patience
0
tontonzunny Posted messages 6 Status Member
 
Hello
as agreed explanation:
I couldn't increment a number in Word via a macro
so I transfer everything through Excel

I create a button and insert a macro that adds one to a number each time it's pressed

this number via the insert table function in Word gets embedded

that's it, if you need more explanation...
thank you
0
m@rina Posted messages 27378 Registration date   Status Moderator Last intervention   11 561
 
Hello,

And if you had asked your question on the site where you found this tutorial, perhaps you would have received an adequate response...

We have added an example to this tutorial, available for download on the page
https://www.faqword.com/index.php/word/faq-word/mise-en-forme/466-serait-il-possible-a-partir-dun-modele-word-dincrementer-un-numero-chronologique-a-chaque-creation-de-document-base-sur-ce-modele

Thank you, Argitxu.

m@rina
0
tontonzunny Posted messages 6 Status Member
 
hello
and if I definitely prefer the seriousness of this forum....
0
m@rina Posted messages 27378 Registration date   Status Moderator Last intervention   11 561
 
Excuse me, but I’m literally LOL!!!
Just so you know, the person best suited to answer this question is, after all, the one who came up with this tip and wrote this article... And in this case, that's me!

As you can see, I answer a lot here and I respond a lot on the site where you found this tip, since it’s my site...

So, it turns out you could have refrained from that comment.

m@rina

PS: So, I removed the example kindly provided by Argitxu (look, another contributor from CCM) since it’s not serious.
1
tontonzunny
 
Good evening
listen, I'm not here to make a fuss about my post....so anyway, thanks
for my next question
0