Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to add background color to headers or footers in Excel sheet while printing?

As we know, we can add contents or picture to the header or footer of a sheet, which will display while printing. But have you ever tried to add background color to the headers or footers? Actually, there is no built-in function can handle it, but here I introduce some roundabout ways to achieve the operation.

Add background color to header or footer by Fill color

Add background color to header and footer by VBA

Insert Workbook information to header or footer in Excel

If you have Kutools for Excel installed, you can apply the Insert Workbook Information utility to quickly insert worksheet name, workbook name, workbook path and name or other information to header or footer or cell. Click for 60 days free trial!
doc add background to header 8
 
Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days.

Add background color to header or footer by Fill color

1. Click Page Layout > Page Setup.
doc add background to header 1

2. In the Page Setup dialog, under Margins tab, type 0 into Top, Header, Bottom and Footer textboxes.
doc add background to header 2

3. Click OK. Then select first row and click Home > Merge & Center.
doc add background to header 3

3. Go ahead to select a color from Fill color list to add background color to the merged cells.
doc add background to header 4

4. Repeat step 2 and 3 to add background color to the footer row you want.

Now the page seems to add background color to header and footer.
doc add background to header 5


Add background color to header and footer by VBA

Here is a VBA code can quickly add background color to header and footer at the same time.

1. Press Alt + F11 keys to enable Microsoft Visual Basic for Applications window.

2. Click Insert > Module, copy and paste below code to the new module.

VBA: Add background color to header and footer

Sub FakeHeaderFooter()
'UpdatebyExtendoffice20180628
    Dim I, J As Long
   Dim xRg As Range
    Dim xRow, xCol As Long
    Dim xRows, xCols As Long
    Dim xDivRow, xDivCol As Long
    Dim xTopArr, xButtArr As Variant
    Dim PageSize1, PageSize2 As Integer
    On Error Resume Next
    xTopArr = Array("Top Left", "", "", "Top Center", "", "", "", "")
    xButtArr = Array("Bottom Left", "", "", "Bottom Center", "", "", "", "")
    PageSize1 = 46
    PageSize2 = 8
    With ActiveSheet.PageSetup
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        .BlackAndWhite = False
    End With
    Set xRg = ActiveSheet.UsedRange
    If xRg Is Nothing Then Exit Sub
    xRows = xRg(xRg.Count).Row
    xCols = xRg(xRg.Count).Column
    If xRows < 46 Then xRows = 46
    If xCol < 8 Then xCol = 8
    xDivRow = Int(xRows / PageSize1)
    xDivCol = Int(xCols / PageSize2)
    If ((xRows Mod PageSize1) > 0) And (xDivRow <> 0) Then xDivRow = xDivRow + 1
    If ((xCols Mod PageSize2) > 0) And (xDivCol <> 0) Then xDivCol = xDivCol + 1
    If xDivRow = 0 Then xDivRow = 1
    If xDivCol = 0 Then xDivCol = 1
    Set xRg = Range("A1").Resize(xDivRow * PageSize1, xDivCol * PageSize2)
    xRow = 1
    xCol = 1
    Cells.PageBreak = xlPageBreakNone
    For I = 1 To xDivRow * PageSize1 Step PageSize1 + 1
        For J = 1 To xDivCol * PageSize2 Step PageSize2
            Cells(I, J).Resize(1, PageSize2) = xTopArr
            Cells(I, J).Resize(1, PageSize2).Interior.ColorIndex = 34
            Cells(I + PageSize1, J).Resize(1, PageSize2) = xButtArr
            Cells(I + PageSize1, J).Resize(1, PageSize2).Interior.ColorIndex = 34
            Rows(I + PageSize1 + 1).PageBreak = xlManual
            Columns(J + PageSize2).PageBreak = xlManual
        Next
    Next
End Sub

doc add background to header 6

3. Press F5 key to run the code, then certain background color has been added to the first row and the 47th row of each sheet which will shown as fake header and footer.
doc add background to header 7

Note: in the code, you can change below scripts to meet your need.

1. Change the header and footer contents as you need in the string:

xTopArr = Array("Top Left", "", "", "Top Center", "", "", "", "")

xButtArr = Array("Bottom Left", "", "", "Bottom Center", "", "", "", "")

2. Change the background color index in this sting:

Cells(I, J).Resize(1, PageSize2).Interior.ColorIndex = 34

Cells(I + PageSize1, J).Resize(1, PageSize2).Interior.ColorIndex = 34


quickly insert page break in every nth row of the worksheet.

In some cases, we need to manually insert page breaks to every row or nth row for printing them as single page, which will wast times. Here Kutools for Excel's Insert Page Break Every Row function can quickly and easily insert page breaks in every nth row by 2 steps.  Click for 60 days free trial!
doc insert page break every row
 
Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days.


Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.