title: Excel macro to insert carriage return
body: <p>In my research, I've encountered two possibilities for inserting a carriage return into a header in a VBA macro, using Chr(10) or Chr(13).  I've even seen code posted by Allen Wyatt at <a href="https://excel.tips.net/T001992_Multiple_Line_Headers_and_Footers.html" rel="nofollow noreferrer">excel.tips.com</a> that seems to do exactly what I'm attempting, but where he asserts it works, I have yet to see success.</p>
  
  <p>Here is the basic code I am attempting to execute:</p>
  
  <pre><code>With ActiveSheet.PageSetup
      .CenterHeader = "&amp;F" &amp; Chr(10) &amp; "&amp;A"
  End With
  </code></pre>
  
  <p>There is other formatting I'm doing, but it all succeeds.  This line only produces the filename in the header ("&amp;F"), but no return and no tab name on the second line.  It also doesn't fail; it just continues right through this line.</p>
  
  <p>This macro was originally recorded by me in Excel 2010, which I then augmented with additional automation for page formatting.  I'm still running it under Excel 2010, and it has never worked correctly on this particular line.  Does anyone have knowledge of what might be transpiring here?</p>
  
  <p>Edit: Here is the full code from the original macro recording and my edits.</p>
  
  <pre><code>Application.PrintCommunication = False
  With ActiveSheet.PageSetup
      .PrintTitleRows = ""
      .PrintTitleColumns = ""
  End With
  Application.PrintCommunication = True
  ActiveSheet.PageSetup.PrintArea = ""
  Application.PrintCommunication = False
  With ActiveSheet.PageSetup
      .PrintTitleRows = "$1:$1"
      .PrintTitleColumns = ""
      .LeftHeader = ""
      .CenterHeader = "&amp;F" &amp; vbCrLf &amp; "&amp;A"
      .RightHeader = ""
      .LeftFooter = ""
      .CenterFooter = ""
      .RightFooter = "Printed &amp;D"
      .LeftMargin = Application.InchesToPoints(0.7)
      .RightMargin = Application.InchesToPoints(0.7)
      .TopMargin = Application.InchesToPoints(0.75)
      .BottomMargin = Application.InchesToPoints(0.75)
      .HeaderMargin = Application.InchesToPoints(0.3)
      .FooterMargin = Application.InchesToPoints(0.3)
      .PrintHeadings = False
      .PrintGridlines = True
      .PrintComments = xlPrintNoComments
      .PrintQuality = 600
      .CenterHorizontally = False
      .CenterVertically = False
      .Orientation = xlPortrait
      .Draft = False
      .PaperSize = xlPaperLetter
      .FirstPageNumber = xlAutomatic
      .Order = xlDownThenOver
      .BlackAndWhite = False
      .Zoom = 100
      .PrintErrors = xlPrintErrorsDisplayed
      .OddAndEvenPagesHeaderFooter = False
      .DifferentFirstPageHeaderFooter = False
      .ScaleWithDocHeaderFooter = True
      .AlignMarginsHeaderFooter = True
      .EvenPage.LeftHeader.Text = ""
      .EvenPage.CenterHeader.Text = ""
      .EvenPage.RightHeader.Text = ""
      .EvenPage.LeftFooter.Text = ""
      .EvenPage.CenterFooter.Text = ""
      .EvenPage.RightFooter.Text = ""
      .FirstPage.LeftHeader.Text = ""
      .FirstPage.CenterHeader.Text = ""
      .FirstPage.RightHeader.Text = ""
      .FirstPage.LeftFooter.Text = ""
      .FirstPage.CenterFooter.Text = ""
      .FirstPage.RightFooter.Text = ""
  End With
  Application.PrintCommunication = True
  </code></pre>