Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 03-26-2021, 01:59 PM
gmaxey gmaxey is offline How to preset serial number in 00000# format Windows 10 How to preset serial number in 00000# format Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 03-27-2021, 06:11 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

Sorry I am not able to get it work. Can you please explain how to do it?
thanks ..
Reply With Quote
  #4  
Old 03-27-2021, 07:12 AM
gmaxey gmaxey is offline How to preset serial number in 00000# format Windows 10 How to preset serial number in 00000# format Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Does this make is simpler?


Rng1.Text = Format(SerialNumber, "00000#")
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 03-28-2021, 12:13 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

Quote:
Originally Posted by gmaxey View Post
Does this make is simpler?


Rng1.Text = Format(SerialNumber, "00000#")
Yes Sir... This works... Thank you very much...
Reply With Quote
Reply

Thread Tools
Display Modes


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 09:32 AM.


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