DH Templates

Trying to create a template in Word 2003 with automatic invoice numbering. Please HELP.?

I have created a new template. I am trying to automate the Invoice Nubmer so that each time I open up the template it shows the next number (ex. 00001, 00002, 00003, 00004, etc) I know it can be done. I now there is a macro but cannot find and am brain dead when it comes to creating a macro. Thank you in advance for any help you can provide.

Public Comments

  1. what you need to do is store a variable which I call invoice_num. This is done with ActiveDocument.Variables To open the VB editor press ALT+F11 From there look for thisdocument and double click on it On the right hand side, there should be a drop down menu with "(general)", switch it to "Document" a new macro should have been generated called Private Sub Document_Open() End Sub Between those 2 lines, copy and paste the code below Dim num As Integer For Each aVar In ActiveDocument.Variables If aVar.Name = "invoice_num" Then num = aVar.Index Next aVar If num = 0 Then ActiveDocument.Variables.Add Name:="invoice_num", _ Value:=1 Else With ActiveDocument.Variables(num) .Value = .Value + 1 MsgBox "Invoice Number = " & .Value End With End If How does it work? First the macro checks if the variable "invoice_num" exists among the variables in the template if no (index value = 0) then the macro creates the variable "invoice_num" and give it the value 1 (first invoice number) if yes, I add 1 to the value of invoice_num and a message box pops up and read invoice number = and whatever the value of invoice_num is.
Powered by Yahoo! Answers