Cómo imprimir desde código VBA

Resulta que quiero imprimir desde código y para esto grabé una macro pero estoy teniendo un error en la parte donde defino el tamaño de la hoja.

Cabe destacar que la impresora es una impresora de facturas (http://www.custom.biz/ticket-printers/q-IIIx-119-7 ), ese es el módelo, por lo tanto el .PaperSize es distinto a los que comunmente aparecen, por lo mismo grabé la macro, pero al usar el código generado me da un error en esa linea: adjunto código...

Sub Macro3()
'
' Macro3 Macro
'
'
    Range("AA1:AB13").Select
    Application.PrintCommunication = True
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    'ActiveSheet.PageSetup.PrintArea = ""
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.236220472440945)
        .RightMargin = Application.InchesToPoints(0.236220472440945)
        .TopMargin = Application.InchesToPoints(0.236220472440945)
        .BottomMargin = Application.InchesToPoints(0.236220472440945)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = 203
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlPortrait
        .Draft = False
        .PaperSize = 217 ' Donde se genera el error...............
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .EvenPage.LeftHeader.Text = ""
        .EvenPage.CenterHeader.Text = ""
        .EvenPage.RightHeader.Text = ""
        .EvenPage.LeftFooter.Text = ""
        .EvenPage.CenterFooter.Text = ""
        .EvenPage.RightFooter.Text = ""
        .FirstPage.LeftHeader.Text = ""
        .FirstPage.CenterHeader.Text = ""
        .FirstPage.RightHeader.Text = ""
        .FirstPage.LeftFooter.Text = ""
        .FirstPage.CenterFooter.Text = ""
        .FirstPage.RightFooter.Text = ""
    End With
    'Application.PrintCommunication = True
    Selection.PrintOut Copies:=1, Collate:=True
End Sub

1 Respuesta

Respuesta
2

José Gabriel, echale un vistazo a esta macro de Elsa Matilde haber como te va:

Sub Macro25()
ActiveSheet.PageSetup.PrintArea = "$S$4:$AB$99" ' RANGO QUE SE DESEA IMPRIMIR.

    With ActiveSheet.PageSetup
        .CenterHorizontally = True   'centrada horizontal y verticalmente
        .CenterVertically = True
        .Zoom = False     'ajuste totalidad de la hoja , 1 de alto x 1 de ancho
        .FitToPagesWide = 1 
        .FitToPagesTall = 1
    End With
    ActiveWindow.SelectedSheets.PrintPreview    'vista preliminar (*)
End Sub

Me comentas como te fue, para brindarte más opciones, si las necesitas.

José Gabriel, he aquí otra opción, esta la uso y me funciona perfectamente:

Sub Imprimir()
Application.ScreenUpdating = False
' Acceso directo: CTRL+m

Range("F2:P47").Select
'ActiveWindow.SelectedSheets.PrintPreview
Selection.PrintOut Copies:=1 ', Collate:=True, IgnorePrintAreas:=False
Range("F3").Select
Application.ScreenUpdating = True
End Sub

Realiza los cambios y adaptaciones que consideres si es el caso. Tiene un método de teclado Ctrl+m.

Lo que pasa es que necesito configurar el tamaño de hoja

Ya lo solucioné, gracias

Gracias por avisar.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas