Imprimir un rango de celdas desde un UserForm VB Excel

Quería saber ¿Existe alguna forma de imprimir, a través de un UserForm, al presionar un botón ("IMPRIMIR"), de la Hoja 2, el rango A1:K34 de mi libro de Excel?

Respuesta
1

Prueba creando esta macro

Sub Impresion()
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    Range("A1:K34").Select
    ActiveSheet.PageSetup.PrintArea = "$A$1:$K$34"
    Application.PrintCommunication = True
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub

y asignasela al boton  "Call Impresion"

Para que establezca ese rango de impresión, ajuste todo a una hoja(porque te saldría en 2) y luego lo envíe a la impresora

[quote]

No olvides valorar la respuesta si te fue de utilidad -

O así

Sub Impresion()
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
      .LeftMargin = Application.InchesToPoints(0.7)
        .RightMargin = Application.InchesToPoints(0.7)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Orientation = xlLandscape
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    Range("A1:K34").Select
    ActiveSheet.PageSetup.PrintArea = "$A$1:$K$34"
    Application.PrintCommunication = True
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub

Ajustando los margenes y la orientacion Horizontal

Hola Sebas.! Funciona pero para la hoja activa, yo trabajo principalmente en la hoja 1, y necesito que, esté en la hoja que esté, imprima la hoja 2, el rango A1:K34. De echo la hoja 2 es solamente para que se imprima este rango, todo el trabajo del Form se vee reflejado en la hoja 1. Si puedes ayudarme seria genial.! 

Sub Impresion()
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
      .LeftMargin = Application.InchesToPoints(0.7)
        .RightMargin = Application.InchesToPoints(0.7)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Orientation = xlLandscape
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    Worksheets(2).PageSetup.PrintArea = "$A$1:$K$34"
    Application.PrintCommunication = True
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub

Perdón me falto la parte de los margenes ahora si

Sub Impresion()
    Application.PrintCommunication = False
    With Worksheets(2).PageSetup
      .LeftMargin = Application.InchesToPoints(0.7)
        .RightMargin = Application.InchesToPoints(0.7)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Orientation = xlLandscape
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    Worksheets(2).PageSetup.PrintArea = "$A$1:$K$34"
    Application.PrintCommunication = True
    Worksheets(2).PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub

Recuerda valorar la respuesta si te a sido útil

¡Gracias Sebas!

Modifique un poco el código para que se ajuste a mi planilla, quedando así:

Private Sub CommandButton6_Click()
    Application.PrintCommunication = False
    With Hoja2.PageSetup
      .LeftMargin = Application.InchesToPoints(0.7)
        .RightMargin = Application.InchesToPoints(0.7)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Orientation = xlLandscape
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    Hoja2.Select
    Range("A1:K34").Select
    Hoja2.PageSetup.PrintArea = "$A$1:$K$34"
    Application.PrintCommunication = True
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
    Hoja1.Select
End Sub

Aun así me fue MUY útil, gracias por tu ayuda.!

Yo no le había puesto que la seleccione para que no vaya a la hoja, pero claro tu adaptas el código a tu necesidad lo que importa es que funcione =) je je

1 respuesta más de otro experto

Respuesta
1

Buscando en Internet encontré el siguiente código para imprimir lo que necesito:

Private Sub CommandButton6_Click()
Hoja2.Range("A1:K34").PrintOut
End Sub

Cumpliendo mis necesidades de impresión. Me gustaría saber si hay alguna forma de que imprima la hoja en formato horizontal, ajustando la hoja a una sola pagina.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas