Automatically generating document numbers

A

aaron

I want to create a macro that generates a consecutive number and places it in the footer and stores it in a separate document log. For instance, if I write a letter to Jane Doe, the macro assigns it # 001. the Next document the macro would assign # 002. The macro would have to lookup the last number assigned and add a 1 to it. I am trying to create a "Master Document List" which I can quickly search, as well as track document production.

I would really appreciate any assistance.
 
D

Doug Robbins - Word MVP

Hi Aaron,

See the article “Creating sequentially numbered documents (such as
invoices)†at:

http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm

That will show you how to generate a number for each document and you could
have a separate log file with a table in it into which you also insert the
number and the details of the document.

For what you really want to do though, it would be best to use an Access
database as the repositry of the details of each document, writing a new
record to a file for each one and getting hold of the number used in an
autonumber field in the database for the number to be used in the document.

That's of course if you have Access.
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.


Hope this helps
Doug Robbins - Word MVP
aaron said:
I want to create a macro that generates a consecutive number and places it
in the footer and stores it in a separate document log. For instance, if I
write a letter to Jane Doe, the macro assigns it # 001. the Next document
the macro would assign # 002. The macro would have to lookup the last
number assigned and add a 1 to it. I am trying to create a "Master Document
List" which I can quickly search, as well as track document production.
 
A

Aaron

Thanks Doug

I followed your instructions regarding the AutoNew macro but get an error each time i try to run it. It is "Compile error: Ambiguous name detected : Autonew. Here is the macro text

Sub AutoNew(

' AutoNew Macr
' Macro created 5/19/2004 by Aaron R. Cohe

Sub AutoNew(

Order = System.PrivateProfileString("C:\Settings.Txt",
"MacroSettings", "Order"

If Order = "" The
Order =
Els
Order = Order +
End I

System.PrivateProfileString("C:\Settings.txt", "MacroSettings",
"Order") = Orde

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#"
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#"

End Su

End Su


Any suggestions

Also, I do have Access.
 
P

Peter Hewett

Hi Aaron

You have two AutoNew procedures declared, one nested within the other!!! You need just the
one and your code should look like this:

Sub AutoNew()
Dim Order As Variant

Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")

If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"Order") = Order

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")

End Sub

HTH + Cheers - Peter
 

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