Printing to Zebra printer not working

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
99
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
99
Also if I remove "on Ne00:" excel crashes and reloads when running the code.
 

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
1,056
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
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.
 

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
99
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.
 

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
1,056
Office Version
  1. 365
  2. 2007
Platform
  1. Windows

ADVERTISEMENT

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.
 

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
99
still popping up with dialog box to select printer after commenting out the line above.
1597244891140.png
 

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
99
HAHAHA I figured it out.....
Application.Dialogs(xlDialogPrinterSetup).Show
commented that out
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,130,157
Messages
5,640,460
Members
417,143
Latest member
boukadidanizar

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
Top