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.
I can make the code work with a Chart as follows![]()
Private Sub Workbook_BeforePrint(Cancel As Boolean) ActiveSheet.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) 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.![]()
Private Sub Workbook_BeforePrint(Cancel As Boolean) ActiveSheet.PageSetup.LeftFooter = Sheet1.Range("a1").Value ActiveChart.PageSetup.LeftFooter = Sheet1.Range("a1").Value End Sub
Robert
Bookmarks