#1
|
|||
|
|||
How to preset serial number in 00000# format
Hi, I am preparing a registration form with a column for serial number. By configuring below macros for the word file am working with i was able to print forms with serial numbers in increment as 1,2,3,4 etc but i was instructed to make the serial numbers to be presented in 000001,000002,000003.... 000101,000102,000103 format. Thanks for your help. Code:
Sub SerialNumber() ' ' SerialNumber Macro ' ' Dim Message As String, Title As String, Default As String, NumCopies As Long Dim Rng1 As Range ' Set prompt. Message = "Enter the number of copies that you want to print" ' Set title. Title = "Print" ' Set default. Default = "1" ' Display message, title, and default value. Dim SerialNumber As String NumCopies = Val(InputBox(Message, Title, Default)) SerialNumber = System.PrivateProfileString("C:\Users\D\Desktop\WORK\settings.txt", _ "MacroSettings", "SerialNumber") If SerialNumber = "" Then SerialNumber = 1 End If Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range Counter = 0 While Counter < NumCopies Rng1.Delete Rng1.Text = SerialNumber ActiveDocument.PrintOut SerialNumber = SerialNumber + 1 Counter = Counter + 1 Wend 'Save the next number back to the Settings.txt file ready for the next use. System.PrivateProfileString("C:\Users\D\Desktop\WORK\settings.txt", "MacroSettings", _ "SerialNumber") = SerialNumber 'Recreate the bookmark ready for the next use. With ActiveDocument.Bookmarks .Add Name:="SerialNumber", Range:=Rng1 End With End Sub |
#2
|
|||
|
|||
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim lngIndex As Long For lngIndex = 1 To 100000 Debug.Print Format(lngIndex, "00000#") Next lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
Sorry I am not able to get it work. Can you please explain how to do it?
thanks .. |
#4
|
|||
|
|||
Does this make is simpler?
Rng1.Text = Format(SerialNumber, "00000#") |
#5
|
|||
|
|||
Yes Sir... This works... Thank you very much...
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Looking for help with creating sequential serial number on one page | 4ener | Word | 9 | 02-24-2019 07:50 AM |
Add a serial number to an invoice | pringle747 | Excel Programming | 6 | 02-19-2015 11:19 AM |
Copy Paste Serial No to Excel in Text format | linan123 | Excel | 1 | 05-02-2014 07:50 PM |
Increase serial number for every print | atomtm | Word | 1 | 06-15-2012 05:39 AM |
Serial Number Issue | rehan5001 | Excel | 1 | 06-08-2011 02:46 AM |