VBA for before print needed please

babycody

Well-known Member
Joined
Jul 8, 2003
Messages
1,395
Hello everyone, I am in need of some code. I would like to be able to enter a number into a cell, and have it change in increments that I specify in another cell. I would also like to specify the number of copies. For example I would enter 2 into a cell, and specify the number be increased by two for every sheet printed. Then I would input how many copies I want into another cell. Everytime each sheet is printed the number would change from 2 to 4 to 6 to 8 etc. This would be for a specific sheet in which I make running total tags for inventory purposes. Thank you very much.
 
You can change the printer using code
It would look something like this
Code:
Dim STDprinter As String
STDprinter = Application.ActivePrinter
Application.ActivePrinter = "yourNetworkPrinter" ' change printer
ActiveSheet.PrintOut 
' prints the active sheet
Application.ActivePrinter = STDprinter 
' change back to standard printer

lenze
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How should I place this in the code you gave me Lenze? I found the same code you just gave me on another site, but I kept getting the debug screen. I even tried it with the port name as some other site suggested.
 
Upvote 0
I really don't know. I did this several years ago, but I've slept since then. The only thing I seem to recall was finding it hard to rundown the printer's name. Try recording a macro changing to the Network computer to get the exact syntax.

lenze
 
Upvote 0
I really don't know. I did this several years ago, but I've slept since then. The only thing I seem to recall was finding it hard to rundown the printer's name. Try recording a macro changing to the Network computer to get the exact syntax.

lenze

Thank you for your help Lenze. The macro recorder was the right idea. This is what I came up with:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim STDprinter As String
If ActiveSheet.Name <> "Running_Total_Tags" Then Exit Sub
Cancel = True 'Adds the option to cancel
Dim i, j, k As Long
On Error GoTo Trap
Application.EnableEvents = False
i = InputBox("Enter the Start Number")
j = InputBox("Enter the increment")
k = InputBox("How May Copies?")
Range("$F$23").Value = i
For x = 1 To k
STDprinter = Application.ActivePrinter
' change printer
Application.ActivePrinter = "HP LaserJet 4250 PCL 6 on Ne02:"
' prints the active sheet
ActiveSheet.PrintOut collate:=False
Range("$F$23").Value = Range("$F$23").Value + j
' change back to standard printer
Application.ActivePrinter = "HP Deskjet 6940 series on Ne03:"
Next x
Trap: Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top