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
 

Forum statistics

Threads
1,081,532
Messages
5,359,359
Members
400,524
Latest member
Excelbat

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top