Results 1 to 2 of 2

Reference a Cell in a Print Header/Footer

Threaded View

  1. #1
    Registered User
    Join Date
    11-12-2011
    Location
    Swansea, Wales
    MS-Off Ver
    Excel 2003
    Posts
    2

    Reference a Cell in a Print Header/Footer

    I have a spreadsheet that contains both Sheets and Charts and I want to Reference the contents of a cell in the header/footer of both types using VB.

    The following Micosoft web site contains a nice simple piece of code that I would like to use if possible - uses the Workbook_BeforePrint method to add the cell contents to the header/footer before printing :-

    http://support.microsoft.com/kb/273028

    The following VB code works when printing a Sheet but not with a Chart.

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
       ActiveSheet.PageSetup.LeftFooter = Sheet1.Range("a1").Value
    End Sub
    I can make the code work with a Chart as follows

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
       ActiveChart.PageSetup.LeftFooter = Sheet1.Range("a1").Value
    End Sub
    My problem - if I combine the two I get an error because if the Sheet is active then the Chart is not, and the reverse of this, the Sheet/Chart that is not active generates the error in the code.

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
       ActiveSheet.PageSetup.LeftFooter = Sheet1.Range("a1").Value
       ActiveChart.PageSetup.LeftFooter = Sheet1.Range("a1").Value
    End Sub
    The ideal solution would be for a simple modification to the above code but I seem to be stuck hence any help would be appreciated.

    Robert
    Last edited by RobHam; 11-13-2011 at 07:31 AM.

Thread Information

Users Browsing this Thread

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

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