I have Brother QL-720NW Label Printer, which I want to print some labels on.
The printer has a roll of width 62mm
When I try to print something to it, I need to setup the page, and define page size. If the page size is incorrect (width more than 62mm) the printer won't print anything.
Now my problem is that I am using excel with macros to send some data to the printer. I know there is some predefined page sizes (http://msdn.microsoft.com/en-us/library/office/ff834612%28v=office.15%29.aspx) which can be used, but in my case all of them are too big for this purpose.
Here a sample of the code I have so far:
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
Now I have 3 questions:
1: At the .PaperSize = xlPaperUser I get a runtime-error '1004'. Unable to set the PaperSize of the PageSetup class. What is wrong here ?
2: How can I set the paper size to something like 62mm x 50mm ?
3: Even that I define the print area to Range("Img") it still print the whole sheet ?!?
By the way I am totally new to vba, this is my first attempt to use vba.