我一直在研究需要打印到标签打印机而不是网络打印机的宏。无论我尝试什么,它都拒绝从默认打印机切换到标签打印机。
请查看以下代码,如果您发现任何错误,请告诉我们:
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-001\MSP-Label2 on Ne07"
End If
End Sub