使用Excel Macro

时间:2018-09-05 18:31:39

标签: excel vba printing

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

请查看以下代码,如果发现错误,请通知我:

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

谢谢!

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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