Help with a macro

J

jonfromdon

Recently we have found the need to print off several copies of a document
onto two part carbon paper and I am hoping that a simple macro will do the
trick. What we require is:
Open a specific document
Find a Bookmarked cell on the document
From a Userform, enter the Start Number into this cell and Total number of
copies required
Print off two copies of this Doc
Increment this number by 1 and replace the previous number and repeat the
print off
Continue to cycle this event until Total Number is reached.
Can anyone help, please
 
G

Graham Mayor

What does the 'start number' represent in relation to the printout? Start
what?
What is the relevance of the bookmarked cell?
If the Start Number has some relevance to the printed output, where, if
anywhere, is the Total to be entered?
Which Word version?
Is the document a protected form?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

jonfromdon

Hi Graham

The Start Number is just a sequential number representing a unique
Certificate Number which is to be placed in the bookmarked cell - this number
is to be automatically advanced by 1 after two copies are printed off.
Both the Start Number and Total Number will have to be entered via a user
form - the Total Number is the number of copies of the Certificate to be
printed off (two copies of each)
Using Word 2003
The form is not protected
 
G

Graham Mayor

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

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

jonfromdon

Hi Graham

Thanks very much - with a little tweak relating to the print instructions
these macros work exactly as required.

Thanks again
 
J

jonfromdon

Help again Graham!!

The macro as described here worked wonderfully up until last week when for
some unexplained reason it now keeps putting ALL the consequtive numbers
"Order" in the Bookmarked box instead on overwriting each selected number.

Help!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top