Reproducing the code for user forms in newsgroup forums is awkward, so this
suggestion does not use one.
The following macros assume a bookmarked table cell (not the cell content)
with the bookmark name "CertNo" to receive the numbers.
The certificate numbers are stored in a text file "Settings.ini" which is
saved for convenience in the Word Startup folder (though you can use another
path if you prefer. The macro reads the next number from the ini file, types
it in the bookmarked cell then prints two copies of the document. The number
is then incremented by one and the process repeated as many times as you
request certificates from the input box. Finally the next number is written
to the ini file for next time.
I have added a macro to reset the certificate number should that be
required.
Sub AddNoFromINIFileToBookmark()
Dim SettingsFile As String
Dim Order As String
Dim iCount As Integer
Dim i As Long
iCount = InputBox("Print how many certificates?", _
"Print Certificates", 1)
'Save invoice number in the Word startup folder.
SettingsFile = Options.DefaultFilePath(wdStartupPath) & "\Settings.ini"
Order = System.PrivateProfileString(SettingsFile, _
"CertificateNumber", "Order")
If Order = "" Then
Order = 1
End If
For i = 1 To iCount
With Selection
.GoTo What:=wdGoToBookmark, _
name:="CertNo"
.TypeText Text:=Format(Order, "00000")
End With
ActiveDocument.PrintOut Copies:="2"
Order = Order + 1
Next
System.PrivateProfileString(SettingsFile, "CertificateNumber", _
"Order") = Order
End Sub
Sub ResetCertificateNo()
Dim SettingsFile As String
Dim Order As String
Dim sQuery As String
SettingsFile = Options.DefaultFilePath(wdStartupPath) & "\Settings.ini"
'SettingsFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) &
"\Settings.ini"
Order = System.PrivateProfileString(SettingsFile, _
"CertificateNumber", "Order")
sQuery = InputBox("Reset Certificate Number?", "Reset", Order)
Order = sQuery
System.PrivateProfileString(SettingsFile, "CertificateNumber", _
"Order") = Order - 1
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>