It's a whole 11 lines of code (if we ignore declarations). Given your requirement - something that Word cannot actually do natively - it is about as simple as you'll get.
That is about as simple as it gets since Word 2000 and later. It was a lot worse in WordBasic in the earlier versions. Almost everything ended up with error 100!
You could always write it in COBOL or whatever language takes your fancy. There is a generic office API which interfaces to most languages as long as they can talk to C libraries.
If you need to print just a number of the copy when printing the same document, there is no macro needed. Save an excel file with a header and a column filled with serial numbers (i.e. "ID" in A1, 1 in A2, 2 in A3 etc.). Now you can do a mail merge using excel data as source, can be combined with any text (Copy no <<ID>> of 10). Send the mail merge to the printer, you can choose a range of records to print.
The question is unclear. Do you want to print a batch of documents at a single time, or the same document (apart from the serial number) at multiple arbitrary times.
The assumption seems to be the latter, and I can't say I'm impressed with either of the linked methods (although I like the idea of coding in Cobol!!), but unique serial number is non-specific.
A GUID would be guaranteed unique but perhaps a little unwieldy. Leaving that aside you need to remember the previous number and the usual way (unless you want to use an external central database) to do that would be with a document variable - remembered behind the scenes and displayed on the document surface. A more modern, if slightly more awkward, alternative could be custom xml attached to a content control.
Whatever method you choose, there are two potential issues - remembering to save the document after printing (which could be accomplished in the VBA - and all methods need some VBA) and always working on the same document - in other words not taking copies of it.
Tell us - exactly - what you want and we can tell you - exactly - how to do it. But don't expect it to be a single line of code!
Enjoy,
Tony
------------------------------------------------------------------------------------ We want to help you; help us to do it by reading this:Before you ask a question.
It looks as though it is more complicated than I would have thought. It probably is not worth doing in the current case. If in the future I decide to print a serial number, I will do it in COBOL, just like the checks.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.