title: Excel VBA Center header/footer "Align Left"
body: <p>Is there any way to align Center Header in Excel? I know there is no any built in solution but is there any VBA code that would work. I have been trying copying cells to header, setting center header with VBA but my Center Header is "Align Center" all the time. </p>
  
  <p>I have even found very complex code to calculate length of sentences and add spaces to each row but it doesn't really work correctly. </p>
  
  <p>I can also set rows to repeat on top and forget about header but what about footer then? How I can set Center Footer to align my two row text to align left? </p>
  
  <p>I have tried:</p>
  
  <pre><code>With ActiveSheet.PageSetup
      .LeftHeader = Range("a1").Value &amp; " " &amp; Range("b1").Value &amp; " " &amp; Range("a2").Value &amp; " " &amp; Range("b2").Value
  End With
  </code></pre>
  
  <p>Also sending named range to header:</p>
  
  <pre><code>Option Explicit
  
  Sub SetCenterHeader()
      Dim txt As String
      Dim myRow As Range
  
      With Range("NorthHead") ' reference named range
          For Each myRow In .Rows ' loop through referenced range rows
              txt = txt &amp; Join(Application.Transpose(Application.Transpose(myRow.Value)), " ") &amp; vbLf ' update 'txt' with current row cells values joined and separated by a blank
          Next
      End With
      ActiveSheet.PageSetup.CenterHeader = Left(txt, Len(txt) - 1) ' set CenterHeader with resulting 'txt' excluding last vblf character
      ActiveWindow.SelectedSheets.PrintOut Copies:=1
  End Sub
  </code></pre>
  
  <p>Result is always the same:</p>
  
  <p><a href="https://i.stack.imgur.com/nv9Ch.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nv9Ch.png" alt="enter image description here"></a></p>