Using VBA code to set printer with variable name

V_is_for_Victory

New Member
Joined
Jul 29, 2010
Messages
2
I have code that searches for the correct network node for the selected printers. The problem is that I have a variable getting set with the address to be passed back to be used as the printer.

Need help. I had this code working and then all of a sudden the code stopped working.

Sub FindShiftPrinter_Click(PrinterName)
Dim Msg As String
Dim C As Integer


CheckShiftPrinter:
C = 0
D = 0

On Error GoTo WrongPrinterError:

ResumePrinting:

If C < 40 Then

If C < 10 Then
PrinterName = "\\VJPRINT3\" & Cells(2, 42) & " on Ne0" & C & ":"
Else
PrinterName = "\\VJPRINT3\" & Cells(2, 42) & " on Ne" & C & ":"
End If
Application.ActivePrinter = PrinterName

Else

If D < 40 Then

If D < 10 Then
PrinterName = "\\VJPRINT4\" & Cells(2, 42) & " on Ne0" & C & ":"
Else
PrinterName = "\\VJPRINT4\" & Cells(2, 42) & " on Ne" & C & ":"
End If
Application.ActivePrinter = PrinterName
End If

End If

Exit Sub

WrongPrinterError:
C = C + 1
D = D + 1
Resume ResumePrinting:
End Sub


Section of the code where printing is done:


If Cells(53, 3) = "" Then

Cells(2, 19) = "Date/Time Printed:"
Cells(2, 21) = PDate & " " & PTime & " 1 page"

With Worksheets("Labor Reporting").PageSetup
.PrintArea = "$C$2:$Z$56"
.Orientation = xlLandscape
.BlackAndWhite = True
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
.CenterHorizontally = True
.CenterVertically = True
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.5)

End With

Else

Cells(2, 19) = "Date/Time Printed:"
Cells(2, 21) = PDate & " " & PTime & " 2 pages"

With Worksheets("Labor Reporting").PageSetup
.PrintArea = "$C$2:$Z$109"
.PrintTitleRows = ActiveSheet.Rows("$10:$12").Address
.Orientation = xlLandscape
.BlackAndWhite = True
.Zoom = False
.FitToPagesTall = 2
.FitToPagesWide = 1
.CenterHorizontally = True
.CenterVertically = False
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.25)
.RightFooter = "&P"

End With

End If

'This Call finds the correct Network Node (NExx) for the designated printer by area

Call FindShiftPrinter_Click(PrinterName)
Worksheets("Labor Reporting").PrintOut ActivePrinter:=PrinterName
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,215,611
Messages
6,125,829
Members
449,266
Latest member
davinroach

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