+ Reply to Thread
Results 1 to 3 of 3

BeforePrint Event - to print a footer on a chart - code works for a normal sheet

  1. #1
    Registered User
    Join Date
    02-13-2021
    Location
    UK
    MS-Off Ver
    365
    Posts
    47

    Question BeforePrint Event - to print a footer on a chart - code works for a normal sheet

    Hello,

    I have the following line of code in the Thisworkbook BeforePrint Event to print a footer.

    It works for a sheet but if I select just a chart to print there is no footer, just the chart itself.

    How can I make it printer a footer on the sheet of a chart?
    (obviously not on the chart itself)



    Private Sub Workbook_BeforePrint(Cancel As Boolean)

    ActiveSheet.PageSetup.LeftFooter = ActiveWorkbook.Name

    End Sub


    Thank you
    Hattie

    Windows 10 pro 64 Bit
    Office 365 64 Bit

  2. #2
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: BeforePrint Event - to print a footer on a chart - code works for a normal sheet

    Well I don't know the reason for this behaviour, but you overcome this easily by just adding a dot, "." in the first cell of the sheet, you can even make the colour white of this dot.

    Cheers
    Erwin
    I started learning VBA because I was lazy ...
    Still developing.... being more lazy...

  3. #3
    Registered User
    Join Date
    02-13-2021
    Location
    UK
    MS-Off Ver
    365
    Posts
    47

    Re: BeforePrint Event - to print a footer on a chart - code works for a normal sheet

    thanks for the reply.

    i solved it by adding the following code, adding ActiveChart

    If Not (ActiveChart Is Nothing) Then
    'Chart does exist
    ActiveChart.PageSetup.LeftFooter = "&8&""Arial""" & ActiveWorkbook.Name & " (" & ActiveSheet.Name & ")"
    ActiveChart.PageSetup.RightFooter = "&8&""Arial""" & Format(Now(), "ddd dd mmm yy")
    ActiveChart.PageSetup.CenterFooter = "&8&""Arial""" & "Page &P of &N"
    End If


    I wrote this from what I read in various places and pieced it together
    so there is probably a more elegant way of doing it. But it works

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 09-22-2020, 01:20 PM
  2. BeforePrint Code won't run when I print anything
    By btb918 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-16-2015, 11:53 AM
  3. Excel 2010, Excel 2013 BeforePrint Event Trigger (Before Print Preview)
    By mikepfly2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2015, 03:43 PM
  4. BeforePrint event does not work for print preview in Excel 2010
    By MSApprentice in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2015, 08:19 PM
  5. [SOLVED] How to format header footer when using BeforePrint to use a cell reference?
    By fbrb99 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2012, 11:47 AM
  6. Print CurrentRegion w/in BeforePrint Event
    By cart0250 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2007, 12:54 AM
  7. Execute code after printing with the BeforePrint event
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2005, 02:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1