Encabezado y Pie de página con Números Romanos con Código VBA

0

 


Código:


Sub Encabezado_PieDePagina_EnNumerosRomanos()

       Dim HojaActiva As Worksheet

       Dim NumeroPaginasHoja As Long

       Dim Indice As Long

       Dim NumeroReinicio As Long


       Set HojaActiva = ActiveSheet

       NumeroPaginasHoja = HojaActiva.PageSetup.Pages.Count

    

       If NumeroPaginasHoja = 0 Then

              MsgBox "No hay nada para imprimir.", vbInformation + vbOKOnly, "Alerta"

       Else

              NumeroReinicio = Application.InputBox _

                                        (Prompt:="• Un número diferente de uno reinicia la numeración en ese número." & _

                                        vbNewLine & "• Un número igual a uno inicia la numeración en uno." & vbNewLine & _

                                        vbNewLine & "Ingrese un valor numérico... (" & NumeroPaginasHoja & _

                                        " páginas detectadas)", Title:="Reiniciar la numeración en...", Default:=1, Type:=1)

        

              If NumeroReinicio = 0 Then

                     Exit Sub

              Else

                     NumeroReinicio = VBA.Abs(NumeroReinicio)

                     Application.ScreenUpdating = False

            

                     For Indice = 1 To NumeroPaginasHoja

                     Application.StatusBar = "Imprimiendo página " & Indice & " de " & NumeroPaginasHoja

                

                     With HojaActiva

                       '//** CABECERA IZQUIERDA **// Use el apostrofe (') para no ejecutar la línea siguiente

                       .PageSetup.LeftHeader = "Página " & Application.WorksheetFunction.Roman(NumeroReinicio, 0)

                    

                       '//** CABECERA CENTRO **// Use el apostrofe (') para no ejecutar la línea siguiente

                       .PageSetup.CenterHeader = "Página " & Application.WorksheetFunction.Roman(NumeroReinicio, 0)

                    

                       '//** CABECERA DERECHA **// Use el apostrofe (') para no ejecutar la línea siguiente

                       .PageSetup.RightHeader = "Página " & Application.WorksheetFunction.Roman(NumeroReinicio, 0)

                    

                       '//** PIE DE PÁGINA IZQUIERDO **// Use el apostrofe (') para no ejecutar la línea siguiente

                       .PageSetup.LeftFooter = "Página " & Application.WorksheetFunction.Roman(NumeroReinicio, 0)

                    

                       '//** PIE DE PÁGINA CENTRO **// Use el apostrofe (') para no ejecutar la línea siguiente

                       .PageSetup.CenterFooter = "Página " & Application.WorksheetFunction.Roman(NumeroReinicio, 0)

                    

                       '//** PIE DE PÁGINA DERECHO **// Use el apostrofe (') para no ejecutar la línea siguiente

                       .PageSetup.RightFooter = "Página " & Application.WorksheetFunction.Roman(NumeroReinicio, 0)

                    

                       .ExportAsFixedFormat Type:=xlTypePDF, _

                           Filename:=ActiveWorkbook.Path & Application.PathSeparator & "Pagina " & Indice & ".pdf", _

                           IgnorePrintAreas:=True, _

                           From:=Indice, _

                           To:=Indice, _

                           OpenAfterPublish:=False

                

                     End With

                           NumeroReinicio = NumeroReinicio + 1

                     Next Indice

            

                  Application.StatusBar = False

                  HojaActiva.PageSetup.CenterHeader = ""

                  HojaActiva.PageSetup.CenterFooter = ""

                  Application.ScreenUpdating = True

              End If

       End If

End Sub


⭐ Si te gustó, por favor regístrate en nuestra Lista de correo y Suscríbete a mi canal de YouTube para que estés siempre enterado de lo nuevo que publicamos.


Entradas que pueden interesarte

Sin comentarios

Etiquetas:
#aprendiendoexcel365, #josealcaldealias, #Excel, #funciones, #UDF, #Visual Basic, #VBA, #DAX, #Tips, #Basico, #Microsoft Excel, #Cursos Excel OnLine, #Aprende Excel, #Aprende Excel OnLine, #Excel 365, #Power Pivot, #Power BI, #Power Query, #Google Sheets, #Macros, #Código VBA, #Tutoriales Excel, #MTV, #Vbscript, #TypeScript, #Lenguaje M, #fórmulas, #funciones, #paso a paso, #funciones Excel, #libros, #tablas, #formatos, #hojas, #datos, #gráfico, #análisis de datos, #base de datos, #dashboards, #tablas dinámicas, #excel desde cero, #hoja de cálculo, #plantillas de Excel