I am using the following macro to insert data into the Header and Footer of a workbook. If I try to use ThisWorkbook.FullName or ThisWorkbook.Name in the LeftFooter property and either is too long, the Macro is throwing the following error: “Run-Time error ‘1004’: Unable to set the LeftFooter property of the Page Setup class.”
Does anyone have any suggestions?
Sub Insert_Header_Footer()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Changing header/footer in " & ws.Name
With ws.PageSetup
.CenterHeader = "&""Calibri,Bold""&16" & _
Worksheets("Workbook Reference Data").Range("B3").Value & _
Chr(10) & "&""Calibri,Bold""&20" & _
Worksheets("Workbook Reference Data").Range("B4").Value & _
Chr(10) & "&""Calibri""&12" & _
Worksheets("Workbook Reference Data").Range("B5").Value
.LeftFooter = "&""Calibri""&8" & _
Worksheets("Workbook Reference Data").Range("B6").Value & _
Chr(10) & "&""Calibri""&8" & _
Worksheets("Workbook Reference Data").Range("B7").Value & _
Chr(10) & ThisWorkbook.FullName
.RightFooter = "&""Calibri""&8" & _
Worksheets("Workbook Reference Data").Range("B4").Value & _
Chr(10) & "&""Calibri""&8" & _
Worksheets("Workbook Reference Data").Range("B5").Value & _
Chr(10) & "Revised &D &T" & Chr(10) & "Page &P of &N"
End With
Next ws
Set ws = Nothing
Application.StatusBar = False
End Sub
Does anyone have any suggestions?
Sub Insert_Header_Footer()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Changing header/footer in " & ws.Name
With ws.PageSetup
.CenterHeader = "&""Calibri,Bold""&16" & _
Worksheets("Workbook Reference Data").Range("B3").Value & _
Chr(10) & "&""Calibri,Bold""&20" & _
Worksheets("Workbook Reference Data").Range("B4").Value & _
Chr(10) & "&""Calibri""&12" & _
Worksheets("Workbook Reference Data").Range("B5").Value
.LeftFooter = "&""Calibri""&8" & _
Worksheets("Workbook Reference Data").Range("B6").Value & _
Chr(10) & "&""Calibri""&8" & _
Worksheets("Workbook Reference Data").Range("B7").Value & _
Chr(10) & ThisWorkbook.FullName
.RightFooter = "&""Calibri""&8" & _
Worksheets("Workbook Reference Data").Range("B4").Value & _
Chr(10) & "&""Calibri""&8" & _
Worksheets("Workbook Reference Data").Range("B5").Value & _
Chr(10) & "Revised &D &T" & Chr(10) & "Page &P of &N"
End With
Next ws
Set ws = Nothing
Application.StatusBar = False
End Sub