我有 Brother QL-720NW 标签打印机,我想在上面打印一些标签。
打印机的卷筒宽度为 62mm
当我尝试对其进行打印时,我需要设置页面并定义页面大小。如果页面尺寸不正确(宽度超过 62 毫米),打印机将不会打印任何内容。
现在我的问题是我正在使用带有宏的 excel 将一些数据发送到打印机。我知道可以使用一些预定义的页面大小(http://msdn.microsoft.com/en-us/library/office/ff834612%28v=office.15%29.aspx),但在我的情况下所有它们对于这个目的来说太大了。
这是我到目前为止的代码示例:
Sub CreateTestCode()
' setting printer
Dim objPrinter As String
objPrinter = ActivePrinter
ActiveSheet.PageSetup.PrintArea = Range("Img")
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
.PrintHeadings = False
.PrintGridlines = False
.RightMargin = Application.InchesToPoints(0.39)
.LeftMargin = Application.InchesToPoints(0.39)
.TopMargin = Application.InchesToPoints(0.39)
.BottomMargin = Application.InchesToPoints(0.39)
.PaperSize = xlPaperUser
.Orientation = xlLandscape
.Draft = False
End With
Dim printerName As String
printerName = "BrotherQL720NW Labelprinter on XYZ"
ActiveSheet.PrintOut Preview:=True, ActivePrinter:=printerName
ActivePrinter = objPrinter
End Sub
现在我有3个问题:
1:在 .PaperSize = xlPaperUser 我收到运行时错误“1004”。无法设置 PageSetup 类的 PaperSize。这里有什么问题?
2:如何将纸张尺寸设置为 62mm x 50mm 之类的?
3:即使我将打印区域定义为 Range("Img") 它仍然打印整张纸?!?
顺便说一句,我对 vba 完全陌生,这是我第一次尝试使用 vba。