Tuesday, June 16, 2020

VBA Header Setup in Excel sheets


Option Explicit

Sub ReplaceAllHeaders()
    Dim i As Long
    For i = 1 To ActiveWorkbook.Sheets.Count
        With Sheets(i).PageSetup
            If Sheets(i).PageSetup.CenterHeader = "" Then
            Sheets(i).PageSetup.CenterHeader = "Header " & i
            Else
                Sheets(i).PageSetup.CenterHeader = Replace( _
                Sheets(i).PageSetup.CenterHeader, "Header", "AppliedK")
            End If
        End With
    Next i
End Sub

No comments:

Post a Comment

Hot Topics