I am creating a MS Word document entirely through C# in VS 2008. I am trying to insert a page break, and when the page break is inserted, instead of inserting it and adding a new page at the bottom, it is inserting a break and adding a page at the top. This results in the first page being the last page.
Here is the code for inserting the page break:
start = 0;
end = 0;
Word.Range rngDoc = Range(ref start, ref end);
rngDoc.Collapse(ref CollapseEnd);
rngDoc.InsertBreak(ref pageBreak);
rngDoc.Collapse(ref CollapseEnd);
Also, each page is consumed by a table, if this helps with the diagnostics
InsertBreaknever inserts after the selection. Note the MSDN remarks:(My emphasis.) To get a break at the end of the page, I think you’ll have to select nothing (as you are here) at the end of the document.
I can’t recall whether the
Documenthas its own range. Can you just get an all-encompassing range frommyDoc.Characters?If not, the first thing I would try is
If that doesn’t work, you might resort to
ComputeStatistics(). Something like this:And then create your range from that value. Wish I could help more, but it’s been a while for me. Good luck!