I am working on setting up a footer that can't be changed. The code I used is
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
'.LeftHeader = "header"
'.CenterHeader = ""
'.RightHeader = ""
.LeftFooter = "footer"
'.CenterFooter = ""
'.RightFooter = ""
End With
End Sub
(Courtesy of a previous thread)
This works perfectly for all my tabs except the Chart that is created by a macro. When I test the above code for that tab by using print preview, I get "Run-time error '1004': Unable to set the LeftFooter property of the PageSetup class"
The chart is made using the following code
Sub MakeAPlot()
'This macro will delete an old plot if it exists and generate a new plot using only the applicable data range
Dim rChartXData As Range
Dim rChartYData As Range
Worksheets("PLOT Data").Cells(6, 1).Select 'select a single cell as the initial plot data
On Error Resume Next ' remove existing chart if exists
Application.DisplayAlerts = False
ActiveWorkbook.Charts("aaa").delete
Application.DisplayAlerts = True
On Error GoTo 0
With ActiveSheet ' determine chart data ranges using only actual data
Set rChartXData = .Range(.Range("G2"), .Range("G2").End(xlDown))
Set rChartYData = rChartXData.Offset(, 1)
End With
With ActiveSheet.Shapes.AddChart.Chart 'create new chart in PLOT DATA
.ChartArea.ClearContents 'clear any existing chart contents
With .SeriesCollection.NewSeries 'add the new series of selected data
m = Sheets("REPORT").Cells(2, "I")
yr = Sheets("REPORT").Cells(2, "J")
.Name = "Report ending " & m & " " & yr 'Chart title
.Values = rChartYData
.XValues = rChartXData
End With
' .ChartType = xl3DColumnStacked
.ChartType = xlColumnStacked 'select the chart type
.Legend.delete 'delete the legend-not needed
.Axes(xlCategory).HasTitle = True 'title the graph and axes
.Axes(xlValue).HasTitle = True
.Axes(xlCategory).AxisTitle.Characters.Text = "bbb"
.Axes(xlValue).AxisTitle.Characters.Text = "ccc"
.Location xlLocationAsNewSheet, "Graph" 'move the graph to its own sheet
With ActiveSheet.PageSetup 'insert header and footer
.LeftHeader = ""
.CenterHeader = "&""Calibri,Bold""&18 issues"
.RightHeader = ""
.LeftFooter = "FOOTER"
.CenterFooter = "&T &D"
.RightFooter = ""
End With
End With
End Sub
Doing some investigating, the cause of the error is supposed to be not having a default printer set-up. I am stuck because I do have a default printer set-up; more confusing for me is that the first code works on every single tab in the workbook EXCEPT the chart. The chart has the same level of protection set as several of the other tabs also; the larger macro handles the protection for the sheets.
Any thoughts on what is triggering the error or what else to check would be greatly appreciated. Thank you.
Bookmarks