How to set a RightHeader of the PageSetup

Is it possible to set a RightHeader?

For example, in VBA....
(It sets the page number)

    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = "&P / &N"
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
    End With

Thanks and best regards,


Yes, this is fully supported with all the options. The simplest way to find out how to do it is to launch APIMate from the Start menu. Then create a file in Excel with the header you want, open the file in APIMate and look at the generated code.

For your example, I got this code from APIMate:

  HeadersAndFooters: THeaderAndFooter;

  xls.NewFile(1, TExcelFileFormat.v2016);  //Create a new Excel file with 1 sheet.

  //Set the names of the sheets
  xls.ActiveSheet := 1;
  xls.SheetName := 'Sheet1';

  xls.ActiveSheet := 1;  //Set the sheet we are working in.

  //Global Workbook Options
  xls.OptionsCheckCompatibility := false;

  //Printer Settings
  HeadersAndFooters := THeaderAndFooter.Create();
  HeadersAndFooters.AlignMargins := true;
  HeadersAndFooters.ScaleWithDoc := true;
  HeadersAndFooters.DiffFirstPage := false;
  HeadersAndFooters.DiffEvenPages := false;
  HeadersAndFooters.DefaultHeader := '&R&P / &N';
  HeadersAndFooters.DefaultFooter := '';
  HeadersAndFooters.FirstHeader := '';
  HeadersAndFooters.FirstFooter := '';
  HeadersAndFooters.EvenHeader := '';
  HeadersAndFooters.EvenFooter := '';

The main difference is that we use &L, &C and &R for left, center and right sections. So the text is &R&P..
If you wanted to write say a left and right header, you would write &LLetf header&RRightHeader