How to Add page x of y to MS Word footer with Visual C++ RRS feed

  • Question

  • Dear Microsoft Technical help:

    I am trying to add "Page x of y" to a word document footer with Visual C++. I found this post for doing it in C#:

    But I don't know the MFC equivalent of "object" in

    object currentPage = Word.WdFieldType.wdFieldPage;
    object totalPages = Word.WdFieldType.wdFieldNumPages;

     I tried:

    COleVariant ovOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
    CSections sections = Doc.get_Sections(); CSection sec1 = sections.get_First(); CHeadersFooters footers = sec1.get_Footers(); CHeaderFooter footer = footers.Item(1); CRange range = footer.get_Range(); CFields fields = range.get_Fields(); range.put_Text(L"Page "); //wdFieldPage = 33 fields.Add(range, COleVariant((short)wdFieldPage), ovOpt, ovOpt); range.put_Text(L" of "); // wdFieldNumPages = 26 fields.Add(range, COleVariant((short)wdFieldNumPages), ovOpt, ovOpt);

    But I was only able to get the number of pages("wdFieldNumPages") printed at left side of the footer(I set paragraph alignment to right). This also erased the other information I tried to display at the left side of the footer by using range.InsertAfter.

    What is the proper way to do it in C++? Please help. Thank you.

    • Edited by plato dov Thursday, March 14, 2019 1:09 PM Improving the question
    Wednesday, March 13, 2019 3:27 PM