Computing.Net > Forums > Programming > Excel VBA - printing sequential #

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel VBA - printing sequential #

Reply to Message Icon

Name: bob999
Date: October 13, 2006 at 05:49:04 Pacific
OS: Windows XP SP2
CPU/Ram: 512
Product: Mesh
Comment:

I have a form in Excel that I have to print a zillion of. The problem is each print out has to have a unique form number for tracking purposes. The number is incremental from 0001 (or just 1 would do) to 9999 etc. How do I make the cell that holds the number automatic to increase the number per printed page?

I have got the following code that works, but i have to press enter each time to print the next numbered page - whereas I want to set the mcro to print 100 or so and then walk away while the printer chugs away.

Sub IncrementandPrint()
Dim iNumber As Integer
Dim iNewNumber As Integer
Dim strCharacters As String
sPrint = InputBox("Enter number of times to Print:")
' Put the Actual cell in here that needs changing!
Range("K1").Select
'Print the first copy with current data.
If Not IsNumeric(sPrint) Then
MsgBox "Number to Print MUST be numeric!"
Exit Sub
Else
'Print the first copy....
ActiveWorkbook.PrintOut 'Many Options here!
iNumber = GetNumericValue(ActiveCell.Value)
If iNumber <= 0 Then
strLeftValue = ""
Else
strLeftValue = Left(ActiveCell.Value, Len(ActiveCell.Value) - iNumber)
End If
iNewNumber = CInt(Right(ActiveCell.Value, iNumber))
For i = 1 To CInt(sPrint) ' Start at 2 since the 1st 1 is printed above...
iNewNumber = iNewNumber + 1

ActiveCell.Value = strLeftValue & CStr(iNewNumber)
ActiveWorkbook.PrintOut 'Many Options here!
MsgBox strLeftValue & CStr(iNewNumber)
Next
End If

End Sub
Function GetNumericValue(s As String) As Integer
'This Sub returns the Amount of characters from the right of a String that are numeric
'Assuming that the characters are always to the left here:
Dim iLoopCounter As Integer
iLoopCounter = 0
For i = Len(ActiveCell.Value) To 1 Step -1
iLoopCounter = iLoopCounter + 1
If Not IsNumeric(Right(ActiveCell.Value, iLoopCounter)) Then Exit For
Next

GetNumericValue = iLoopCounter - 1

End Function

*****
Any help would be much appreciated!

bob999



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: October 13, 2006 at 10:51:26 Pacific
Reply:

Take a look at this solution: http://www.rondebruin.nl/print.htm#...

Michael J


0

Response Number 2
Name: bob999
Date: October 17, 2006 at 01:06:24 Pacific
Reply:

Thanks for the quick reply Michael. Unfortunately that macro does not increment the page number - it simply prints the same form with the same number "n" times (the same as a normal "File Print").

If I set the number of prints to 10 I want to get ten pages numbered consecutively from 1 to 10.

Bob

bob999


0

Response Number 3
Name: bob999
Date: October 17, 2006 at 01:45:41 Pacific
Reply:

Michael - my apologies, I made a few changes to the macro and it now works fine!!

My only remaining problem is that it always starts from number "1", whereas if I print sheets regularly I want to resume from the last number that I left off from at my last session.

The macro now looks like this (my next print number is stored in cell K1)

Sub PrintCopies_ActiveSheet()
Dim CopiesCount As Long
Dim CopieNumber As Long
CopiesCount = Application.InputBox("How many Copies do you want?", Type:=1)

For CopieNumber = 1 To CopiesCount
With ActiveSheet
'number in cell K1 (prints "n")
.Range("K1").Value = CopieNumber

'number in cell K1 (prints "n of z")
'.Range("K1").Value = CopieNumber & " of " & CopiesCount

'number in the footer (prints "n of z")
'.PageSetup.LeftFooter = CopieNumber & " of " & CopiesCount

'Print the sheet
.PrintOut
End With
Next CopieNumber
End Sub

bob999


0

Response Number 4
Name: Michael J (by mjdamato)
Date: October 17, 2006 at 08:59:52 Pacific
Reply:

I'm not too familiar with VB, so I can't provide any code. But, I can help with the logic.

Instead of making your CopieNumber loop go from 1 to copiesCount you first need to grab the value of cell K1 and make your CopieNumber loop go from 1+K1 to copiesCount+K1.

Michael J


0

Response Number 5
Name: bob999
Date: October 24, 2006 at 09:01:30 Pacific
Reply:

Hi Michael,
Many thanks for getting back to me again on this query. I'm no VB expert myself, so have asked Rob DeBruin (author of the original VB code) if he can help out.

Thanks again for your time and effort!!

bob999


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

audio driver emulating a ... Mail Merge using VB



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Excel VBA - printing sequential #

Excel VBA Problem saving file www.computing.net/answers/programming/excel-vba-problem-saving-file-/14722.html

excel vba macro assistance www.computing.net/answers/programming/excel-vba-macro-assistance/10837.html

Excel Vba Code www.computing.net/answers/programming/excel-vba-code-/14879.html