Printing to Zebra printer not working

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
203
Office Version
  1. 2013
Platform
  1. Windows
All,

I'm having an issue with the code listed below. When I click submit it just pops up a dialog box to select which printer to use instead of just printing to the targeted active printer. Any ideas?

VBA Code:
Private Sub Submit_Click()
Dim ws          As Worksheet
Dim ws1         As Worksheet
Dim txt1Val     As String
Dim lastRow     As Long

Worksheets("label template").Visible = False

    With Me
        txt1Val = .tooltb.Value
    End With
    
    Set ws = ThisWorkbook.Worksheets(txt1Val)
        ws.Activate

lastRow = ws.Range("A" & Rows.Count).End(xlUp).row + 1

ws.Range("A" & lastRow).Value = Date
ws.Range("B" & lastRow).Value = badgetb.Text
ws.Range("C" & lastRow).Value = depcb.Text
ws.Range("D" & lastRow).Value = assemtb.Text
ws.Range("E" & lastRow).Value = wotb.Text
ws.Range("F" & lastRow).Value = rtstb.Text
ws.Range("G" & lastRow).Value = atmtb.Text
ws.Range("H" & lastRow).Value = bitcb.Text
ws.Range("I" & lastRow).Value = badgetb.Text

Worksheets("label template").Visible = True

    Set ws1 = ThisWorkbook.Worksheets("Label Template")
        ws1.Activate

ws1.Range("b1").Value = tooltb.Value
ws1.Range("b2").Value = atmtb.Value & " in. lbs."
ws1.Range("b3").Value = "(" & Date & ")"
ws1.Columns("A:B").AutoFit

Dim StrPrn As String
StrPrn = Application.ActivePrinter
Application.ActivePrinter = "ZDesigner TLP 2824 Plus (ZPL) on NE00:"
With ActiveSheet
  With .PageSetup
    .FitToPagesWide = 1
    .FitToPagesTall = 1
  End With
      With .PageSetup
        .PrintArea = "A1:B3"
        Application.Dialogs(xlDialogPrinterSetup).Show
        ActiveSheet.PrintOut
        Application.ActivePrinter = StrPrn
      End With
  'MsgBox Application.ActivePrinter
End With

ws1.Range("b1").Value = ""
ws1.Range("b2").Value = ""
ws1.Range("b3").Value = ""

Worksheets("label template").Visible = False

badgetb.Value = ""
tooltb.Value = ""
depcb.Value = ""
assemtb.Value = ""
wotb.Value = ""
rtstb.Value = ""
atmtb.Value = ""
bitcb.Value = ""

Workbooks("book1.xlsm").Save

Unload Me
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Also if I remove "on Ne00:" excel crashes and reloads when running the code.
 
Upvote 0
Hi there. My guess is that the string you have used to set the active printer is wrong.
Application.ActivePrinter = "ZDesigner TLP 2824 Plus (ZPL) on NE00:"

Is it always the first network printer? Before running the macro, try setting the active printer as you want, then msgbox the active printer and see if its correct.
 
Upvote 0
1597242062128.png
Thanks for the reply. Not sure what you mean by first network printer, however the response I get when requesting the active printer is above.
 
Upvote 0
It was only if you had a number of network printers on your pc.
OK. Switching printers in vba especially in excel can be a pain. Try commenting out the line
Application.ActivePrinter = "ZDesigner TLP 2824 Plus (ZPL) on NE00:"
that tries to set it, and see what happens then.
 
Upvote 0
still popping up with dialog box to select printer after commenting out the line above.
1597244891140.png
 
Upvote 0
HAHAHA I figured it out.....
Application.Dialogs(xlDialogPrinterSetup).Show
commented that out
 
Upvote 0
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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