Impresión de una macro guarda copia

Estas son las propiedades de impresión

Sub Macro2()
'
' Macro2 Macro
'

'
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints()
.RightMargin = Application.InchesToPoints()
.TopMargin = Application.InchesToPoints()
.BottomMargin = Application.InchesToPoints()
.HeaderMargin = Application.InchesToPoints(0.12)
.FooterMargin = Application.InchesToPoints()
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints()
.RightMargin = Application.InchesToPoints()
.TopMargin = Application.InchesToPoints(0.12)
.BottomMargin = Application.InchesToPoints()
.HeaderMargin = Application.InchesToPoints()
.FooterMargin = Application.InchesToPoints()
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints()
.RightMargin = Application.InchesToPoints()
.TopMargin = Application.InchesToPoints()
.BottomMargin = Application.InchesToPoints()
.HeaderMargin = Application.InchesToPoints()
.FooterMargin = Application.InchesToPoints(0.13)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints()
.RightMargin = Application.InchesToPoints()
.TopMargin = Application.InchesToPoints()
.BottomMargin = Application.InchesToPoints(0.13)
.HeaderMargin = Application.InchesToPoints()
.FooterMargin = Application.InchesToPoints()
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.13)
.RightMargin = Application.InchesToPoints()
.TopMargin = Application.InchesToPoints()
.BottomMargin = Application.InchesToPoints()
.HeaderMargin = Application.InchesToPoints()
.FooterMargin = Application.InchesToPoints()
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints()
.RightMargin = Application.InchesToPoints(0.13)
.TopMargin = Application.InchesToPoints()
.BottomMargin = Application.InchesToPoints()
.HeaderMargin = Application.InchesToPoints()
.FooterMargin = Application.InchesToPoints()
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$B$2:$F$10"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.13)
.RightMargin = Application.InchesToPoints(0.13)
.TopMargin = Application.InchesToPoints(0.12)
.BottomMargin = Application.InchesToPoints(0.13)
.HeaderMargin = Application.InchesToPoints(0.12)
.FooterMargin = Application.InchesToPoints(0.13)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = Array(600, 300)
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 0
.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
End Sub

1 respuesta

Respuesta
1

Ahora dime, ¿qué necesitas para esta pregunta?

Lo que pasa es que el código de arriba como ya viste genera una copia de un rango en especifico.. lo único que necesito es que que cuando ya este generada esa copia (que sirve como consulta) cuando yo quiera consultar y ver lo que hay... este se pueda imprimir sin apretar ctrl+p si no con tan solo un F3 o algún F.

Pero al imprimir me respete mis condiciones que es un margen personalizado y de manera horizontal...

No veo en dónde se genera la copia, puedes mostrarme.

¿Ese rango lo copia y dónde lo pega en...?

Si ya estableciste en la hoja cómo quieres la impresión, solamente asigna la macro:

Activesheet. Printout

A una F3 o la que quieras y solamente se imprimirá lo que hayas establecido.

esta es la macro que genera la copia de la hoja que es independinete

Sub guardaCopiaPANADERIA()
Application.ScreenUpdating = False
'On Error Resume Next
'x Elsamatilde
Sheets("PANADERIA").Select ' ES LA HOJA A COPIAR
'controla si existe hoja COPIA sino la crea
Dim X As Byte
For Each Sh In Sheets
If Sh.Name = "PANADERIA COPIA" Then X = 1 ' ES LA HOJA A CREAR EN CASO DE
Next Sh
'si la variable esta en 0 debe crear la hoja
If X = 0 Then
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "PANADERIA COPIA" ' ES LA HOJA A CREAR EN CASO DE
'vuelvo a mi hoja
Sheets("PANADERIA").Select ' ES LA HOJA A COPIAR
End If
'copio el rango de datos en la misma ubicaciòn de hoja copia

ActiveSheet.Range("B2:AE370").Copy Destination:=Sheets("PANADERIA COPIA").Range("B2") ' ES LA HOJA A CREAR EN CASO DE
'quito formulas de la copia

Sheets("PANADERIA COPIA").Select ' ES LA HOJA A CREAR EN CASO DE
ActiveSheet.Range("B2:AE370").Select
With Selection.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
Selection.Copy
Selection.PasteSpecial xlValues

'asigno ruta y nombre para la copia. El nombre concatena fecha y nro
ruta = ThisWorkbook.Path & "\COPIAS PANADERIA\" 'NOMBRE DE CARPETA
fini = Range("B" & Rows.Count).End(xlUp).Row
nbrecopia = Format(Range("B" & fini - 1), "dd-mm-yyyy") & "_" & Range("B" & fini)

'creo libro como copia de esta hoja
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
'le agrego las instrucciones de bloqueo y protección
'.Sheets(1).Columns("J:K").Hidden = True 'OPCIONAL: ocultar col
.Sheets(1).Columns("A:AE").EntireColumn.AutoFit 'ajusta ancho de col

'vista Pantalla completa
Application.DisplayFullScreen = True
'se oculta la barra de fórmulas
Application.DisplayFormulaBar = False
With ActiveWindow
'se ocultan las pestañas de las hojas
.DisplayWorkbookTabs = True
'se quitan los encabezados y líneas de las celdas
.DisplayHeadings = False
.DisplayGridlines = False
Application.CommandBars("Worksheet Menu Bar").Enabled = False
'QUITAR BARRAS MACROS
'With ActiveWindow
'OCULTAR LAS PESTAÑAS DE LAS HOJAS DEL LIBRO
.DisplayWorkbookTabs = False
Application.DisplayFullScreen = True ' PANTALLA COMPLETA
ActiveWindow.DisplayVerticalScrollBar = False 'OCULTA BARRA DE DESPLAZAMIENTO VERTICAL
ActiveWindow.DisplayHorizontalScrollBar = False 'OCULTA BARRA DE DESPLAZAMIENTO HORIZONTAL

End With
'se bloquean todas las celdas y se protege la hoja
.Sheets(1).Cells.Locked = True

.Sheets(1).Protect password:="1234"
'contemplo posible error en el guardado
On Error GoTo sinCopia

'contemplo posible error en el guardado
On Error GoTo sinCopia
'guardamos el libro en la misma carpeta, subcarpeta COPIAS
.SaveAs ruta & nbrecopia & ".xlsx"
On Error GoTo 0
'cerramos el nuevo libro
.Close
End With
'se libera el objeto
Set wb = Nothing
'limpio la hoja COPIA
ActiveSheet.Unprotect
ActiveSheet.Cells.Clear
ActiveSheet.Range("B2").Select
'vuelvo a la hoja FACTURA para seguir con el proceso
Sheets("PANADERIA").Select ' REGRESO A HOJA QUE QUIERO
Exit Sub

sinCopia:
MsgBox "Fallo el guardado. Guarda la hoja COPIA manualmente y luego borra su contenido.", , "ERROR"
'vuelvo a la hoja FACTURA para seguir con el proceso
Sheets("PANADERIA").Select ' REGRESO A HOJA QUE QUIERO
End Sub

Supongo que primero generas la copia.

Después pon en la tecla F3 la macro2.

Al principio de la macro2 agrega esta línea:

Sheets("PANADERIA COPIA").select

Cada que presiones la tecla F3 se seleccionará la hoja3, se establecerá todo lo que necesitas para la impresión y al final de la macro agrega esto, para que se imprima:

Activesheet. Printout

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas