open invoice and have a sequential number assigned automatically

  • Thread starter Microsoft word nurd
  • Start date
M

Microsoft word nurd

I want to create an invoice in word and each time the template is opened an
invoice number is assigned automatically and in sequential order.
 
M

Microsoft word nurd

thank you Lene, i tried it but the number is inserted before the previous
number ie. 030201 where i only want 03 because 02 and 01 have been printed
already. I think it has something to do with the InsertBefore command. Can
you help me to have just the current number show in the invoice before it is
saved. thank you.
 
L

Lene Fredborg

Note that the article says “In the _template_ from which you create the
document, insert a bookmark …â€.

The idea is to create a template for your invoice. Each time you want to
create a new invoice, create a new document based on the template. The
problem you describe indicates that you do not create a new document based on
a template but that you open an invoice you have already used and run the
macro in that document. Is that correct?

If you need help on creating a template, see:
http://word.mvps.org/FAQs/Customization/CreateATemplatePart1.htm

Note that it would be possible to change the macro so that it works in an
already used invoice but it is better to create a template. However, if you
would like to reuse an existing invoice, you can replace the line (your
version has been adjusted a bit):

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")

with the following code:

Dim oRange As Range
Set oRange = ActiveDocument.Bookmarks("Order").Range
oRange.Text = Format(Order, "00#")
ActiveDocument.Bookmarks.Add "Order", oRange
Set oRange = Nothing

This will insert the number inside the bookmark instead of after the
bookmark. For further details, see:
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
M

Microsoft word nurd

Thanks again Lene, i guess this stuff is beyond my scope. I read about
templates and they are just formats not a document master like an invoice.
Incidently i called it an invoice but it is actually catering contracts. We
dont want to re-type the text part of the contract into the template each
time we do a new one. I am trying to set up an audit trail to keep track of
catering contracts because the contract is also the instructions to the
server etc and they are flying all over the place (different departments). I
wanted to be able to keep track of the contracts by numbers so i know when i
am missing one. The actual invoice to the customer is done in the restaurant
program "Maitred". They invoice off the contract and if they unknowingly or
uncaringly misplace the contract then the customer is not billed. I dont
really need to have a new saveas filename:="path" & Format(Order, "00#") with
each contract because they are saved by the customer name for easy tracking
later for revisions etc. I just need each new one printed out to be assigned
a sequential number for an audit trail. Can you point me in the right
direction? Also you are right i had to run the macro in the document to
change the number.
big word nurd
 
L

Lene Fredborg

It is correct that a template is used to supply a document with the correct
format but a template can also hold whatever content can be found in a Word
document (hundreds of pages if you wish). Create a template that holds the
exact starting point for a new catering contract (or whatever you are going
to use it for), and any new document you create based on that template will
include exactly that content.

Also note that the macro in the article I posted first was only meant as a
starting point. You can change it as you wish. I you do not want the document
to be saved, then remove the SaveAs line.

In order for you to understand the power of using a template with the
AutoNew macro in it, I suggest you try this:
1. Open one of the documents you have already made and try to save it as a
template (a .dot file). Make sure you have the “Order†bookmark in place.
Store the template in the folder specified in Tools > Options > File
Locations tab as the User Templates folder (TIP: In Word 2003, when you
select Save As and select “Document Template (*.dot)†as the file type, Word
automatically switches to the Templates folder. Give the template an
appropriate name.

2. While your new template is open, store the AutoNew macro in the template
– you can copy the macro from where you have it now (if you need help, see
e.g. http://word.mvps.org/faqs/macrosvba/CreateAMacro.htm - follow the first
line carefully so that you store the macro in the correct template).

3. Now try to create a new document based on the template: Select File >
New. In the panel to the right, clic “On my computerâ€. In the dialog box that
opens, make sure the “General†tab is selected. Find your new template,
double-click it – and voila, you have a new document that looks exactly as
the template you created – and the number in the “Order†bookmark has been
updated due to the AutoNew macro that is automatically executed when you
create a new document based on the template.

I hope this helps.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
M

Microsoft word nurd

Hi Lene, i've been busy since the 15th but i wanted to thank you for your
help. I learned alot playing with the macro you have me and also making what
i needed in a routine to work. i took out the auto from the macro name
(autonew) and used that macro inside a macro i recorded to assign a contract
# and save document after it had been filled out and was a valid contract. I
also put a button on the toolbar to run my simple macro. Thanks for your
help. I went on your website and must say if you are in Denmark your written
english and grammer is excellent. Once again thank you. Have a good day
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top