我已经使用xlwings自动化了我需要的很多东西。
我的Python的最后阶段是打印标签。
Sub Print_Label()
Print_Label Macro
Prints Loan Label
Range("C2:C8").Select
Application.Dialogs(xlDialogPrinterSetup).Show
Selection.PrintOut Copies:=Range("A10"), Collate:=True
End Sub
使用VBA和Python创建标签,然后使用xlwings代码触发打印。
import xlwings as xw
wb = xw.Book(file.xlsm')
your_macro = wb.macro('Print_Label')
your_macro()
这会在Excel中弹出一个对话框,要求通过OK按钮使用哪个打印机。我需要它成为一台特定的打印机并在后台自动运行。
到底是不是-VBA-
Worksheets("Print").Activate
Worksheets("Print").Range("C2:C8").Select
Application.ActivePrinter = "ZDesigner ZM400 200 dpi (ZPL) on LAN_"
Selection.PrintOut Copies:=Worksheets("Print").Range("A10"), Collate:=True