Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-26-2021, 10:57 AM
DarkNinja DarkNinja is offline How to preset serial number in 00000# format Windows 10 How to preset serial number in 00000# format Office 2019
Novice
How to preset serial number in 00000# format
 
Join Date: Mar 2021
Posts: 3
DarkNinja is on a distinguished road
Default 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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to preset serial number in 00000# format 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
How to preset serial number in 00000# format Copy Paste Serial No to Excel in Text format linan123 Excel 1 05-02-2014 07:50 PM
How to preset serial number in 00000# format Increase serial number for every print atomtm Word 1 06-15-2012 05:39 AM
How to preset serial number in 00000# format Serial Number Issue rehan5001 Excel 1 06-08-2011 02:46 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:11 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft