Forum Discussion

rickrpr's avatar
rickrpr
Copper Contributor
Aug 03, 2020

Simple macro Excel 2010

Hello.

 

I'm trying to execute a simple macro to print information on the footer of actice sheet using Excel 2010.

 

When I record a macro personalizing the footer:

 

Left footer -> Page: &[Page] of &[Pages]

Right footer -> &[Date] - &[Hour]

 

After 2nd running of macro the footer is not completed and the print out info is not complete, like:

Left footer -> Page: &

Right footer -> &[Date] -

 

Is it related to specific setup?

 

Thanks!

 

1 Reply

  • NikolinoDE's avatar
    NikolinoDE
    Platinum Contributor

    rickrpr 

    Do it yourself quickly with VBA header and footer. Simply in one module and adjust as needed.

     

    Option Explicit
    
    Sub Set_Print_Header_footer ()
    With ActiveSheet.PageSetup
    '.PrintArea = "A1:F60" 'Area 1
    '.PrintArea = "CS1:DG60" 'Area 2
    ActiveSheet.PageSetup.PrintArea = "G1:U60"
    
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Fett""" & "&14" & "BEST_Sheet_Header" & " - " & Format(Range("E4").Value, "mmmm yyyy ")
    ActiveSheet.PageSetup.LeftHeader = "&""Arial,Fett""" & "&14" & "My Company" & Chr(10) & Range("A3") & Chr(10) & Range("F4")
    ActiveSheet.PageSetup.LeftFooter = "&""Arial,Fett""" & "&10" & "Call me..my phone is…"
    'etc......
    End With
    Application.CommandBars.ExecuteMso "PrintPreviewAndPrint"
    End Sub

     

    If you find this helpful, please mark it as "Best Answer" and as Like (click thumbs up), it will be beneficial to more Community members reading here.

     

    Nikolino

    I know I don't know anything (Socrates)

Resources