Hack 77 Number Documents Sequentially![]() ![]() as invoices and purchase orders. Those numbers usually must go in order and can't repeat. This hack shows you how to use Word to keep track of the numbering for you.If you need to generate invoices for a business, you might save time using a premade invoice template, such as the ones available from the Microsoft web site. One such template is pictured in Figure 8-14. Figure 8-14. You can download an assortment of premade templates from Microsoft.com![]() to mark the items you replace when filling out the templatefor example, the invoice number field, which you replace with the correct number manually.But how do you remember the last number you used? What if multiple users create invoices from the same template? A quick change to the invoice field and an AutoMacro [Hack #60] will give you a self-sequencing invoice template.Create your own new template, either by downloading the Invoice template from Microsoft's web site (you can get there quickly in Word 2003 from the New Document Task Pane [Hack #9]) or by saving a new, blank document as a template.Put your cursor at the spot in your template where you want the invoice number to appear. Select Insert DocVariable, and click the Field Codes button to display the dialog box shown in Figure 8-15. Enter InvoiceNumber in the "Field codes" box, as shown in Figure 8-15. Figure 8-15. Inserting a DOCVARIABLE field![]() number. 8.9.1 The CodeSelect Tools the following macro in your template: Sub AutoNew( )This macro uses a Config file [Hack #67] named C:\InvoiceTemplate.ini to track the invoice number. If the file doesn't exist yet, the macro creates one and starts the numbering at 1. The macro then puts the number from the file into a document variable named InvoiceNumber, which is referenced by the field you inserted in the template. Document variables are similar to document properties (which you view by choosing File created, modified, and deleted only from a macro.Save the changes and close your template. Now select File Each new document created from this template will have an invoice number one higher than the previous document.If you need to modify the numbering, open the InvoiceTemplate.ini file with any text editor, as shown in Figure 8-16. Figure 8-16. Editing the invoice number![]() from the template to run the AutoNew macro and generate the InvoiceTemplate.ini file. Next, open InvoiceTemplate.ini in a text editor and change it to read Number=100. The next invoice based on the template will be numbered 100. |