使用 Excel 宏打印到标签打印机



我一直在研究一个宏,需要打印到标签打印机而不是网络打印机。无论我尝试什么,它都拒绝从默认打印机切换到标签打印机。

请查看以下代码,如果您发现任何错误,请告诉我:

Private Sub CommandButton2_Click()
Dim Box As String
Box = MsgBox("Are you sure you want to print this label " _
& "?", vbQuestion + vbYesNo)
If Box = vbNo Then
Exit Sub
Else: ThisWorkbook.Worksheets("Label").PrintOut ActivePrinter:="MSP-Label2 on msp-dc-001"
End If
End Sub

谢谢!

尝试让用户选择打印机,看看这是否有效:

Private Sub CommandButton2_Click()
Dim box As String
box = MsgBox("Are you sure you want to print this label?", vbQuestion + vbYesNo)
If box = vbNo Then
Exit Sub
Else
If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
ThisWorkbook.Worksheets("Label").PrintOut Copies:=1
End If
End Sub

我终于想通了! 以下代码有效:

Private Sub CommandButton1_Click()
Dim Box As String
Box = MsgBox("Are you sure you want to print this label " _
& "?", vbQuestion + vbYesNo)
If Box = vbNo Then
Exit Sub
Else: ThisWorkbook.Worksheets("Label").PrintOut ActivePrinter:="\msp-dc-001MSP-Label2 on Ne07"
End If
End Sub

最新更新