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

问题描述 投票:0回答:2

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

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

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

谢谢!

excel vba printing
2个回答
1
投票

尝试让您的用户选择一台打印机,看看是否有效:

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

0
投票

我终于明白了!以下代码有效:

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-001\MSP-Label2 on Ne07"
End If
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.