Number copies printed

J

JoeP

I am new at creating code for macros. I have a created a one page document
that is numbered. I would like for the number to increase (in regular
increments of 1) with each copy printed so that I do not have to manually
change the number before each print.

I found the following code at the site
http://www.word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm

but when I run the macro I get stopped at this part of the code...

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"Order") = Order

Here is the code I am using...

Sub AutoNew()

Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")

If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"Order") = Order

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")

End Sub

Any help would be appreciated.

JoeP
 
G

Graham Mayor

The macro you have quoted does not do what you have asked, i.e. print
numbered copies. The following macro will do that for any document.

Sub PrintNumberedCopies()
Dim NumCopies
Dim startNum
Dim oRng As Range

If MsgBox("The number will be placed at the cursor. Is the cursor placed " _
& "at the correct position?", vbYesNo) = vbNo Then End
If ActiveDocument.Saved = False Then
If MsgBox("Do you want to save any changes before" & _
"printing?", vbYesNo) = vbYes Then
ActiveDocument.Save
End If
End If
NumCopies = Val(InputBox("Enter the number of copies " & _
"that you want to print", "PrintNumbered Copies ", 1))
startNum = Val(InputBox("Enter the starting number", "Start at:", 1))

ActiveDocument.Bookmarks.Add name:="CopyNum", Range:=Selection.Range
Set oRng = ActiveDocument.Bookmarks("CopyNum").Range
Counter = startNum - 1
While Counter < NumCopies + startNum - 1
Counter = Counter + 1
oRng.Delete
oRng.Text = Counter
ActiveDocument.PrintOut
Wend
End Sub


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

My web site www.gmayor.com

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

JoeP

Wonderful thank you.

Graham Mayor said:
The macro you have quoted does not do what you have asked, i.e. print
numbered copies. The following macro will do that for any document.

Sub PrintNumberedCopies()
Dim NumCopies
Dim startNum
Dim oRng As Range

If MsgBox("The number will be placed at the cursor. Is the cursor placed " _
& "at the correct position?", vbYesNo) = vbNo Then End
If ActiveDocument.Saved = False Then
If MsgBox("Do you want to save any changes before" & _
"printing?", vbYesNo) = vbYes Then
ActiveDocument.Save
End If
End If
NumCopies = Val(InputBox("Enter the number of copies " & _
"that you want to print", "PrintNumbered Copies ", 1))
startNum = Val(InputBox("Enter the starting number", "Start at:", 1))

ActiveDocument.Bookmarks.Add name:="CopyNum", Range:=Selection.Range
Set oRng = ActiveDocument.Bookmarks("CopyNum").Range
Counter = startNum - 1
While Counter < NumCopies + startNum - 1
Counter = Counter + 1
oRng.Delete
oRng.Text = Counter
ActiveDocument.PrintOut
Wend
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>




.
 

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