none
Stop New Section From Getting Primary Header RRS feed

  • Question

  • Hi there,

    I am automating the creation of a word document that has a different first page header from the rest of the document.  It works fine until I create a new section in the document.  I do this primarily as I want the new section to have text columns.  What happens is the first page of the new section ends up with the first page / primary header, how do I stop this from happening?

    little more info on what is happening below

    ---

    [page 1 header style 1]

    [page 3 header style 2]

    [page 4 header style 2]

    [page 5 header style 2]

    [page 6 header style 1 - with columns]

    [page 7 header style 2 - with columns]

    [page 8 header style 2 - with columns]

    [page 9 header style 2 - with columns]

    ---

    what i want is this,

    ---

    [page 1 header style 1]

    [page 3 header style 2]

    [page 4 header style 2]

    [page 5 header style 2]

    [page 6 header style 2 - with columns]

    [page 7 header style 2 - with columns]

    [page 8 header style 2 - with columns]

    [page 9 header style 2 - with columns]

    Nick.


    Somewhere out there...

    Saturday, September 26, 2015 11:33 AM

All replies

  • Go to the first page of section 2.

    Double-click in the header, or click Header > Edit Header on the Insert tab of the ribbon.

    Clear the check box Different First Page. This will apply to the current section only.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, September 26, 2015 12:10 PM
  • I'm automating it, in C#, using COM.

    Somewhere out there...

    Saturday, September 26, 2015 12:40 PM
  • I hope someone else can help you with that, I don't speak C#.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, September 26, 2015 12:46 PM
  • test

    Ryan P. Casey • www.aimreportwriting.com (Blog)

    Sunday, September 27, 2015 2:30 AM
  • Hi Firkinfedup,

    You could set the PageSetup.DifferentFirstPageHeaderFooter property to define if a different header or footer is used on the first page.

    Here is a simple code:

                Section sction = word.ActiveDocument.Sections[1];
                sction.PageSetup.DifferentFirstPageHeaderFooter = 0;

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, September 28, 2015 3:10 AM
  • Hi Nick

    It's not quite clear exactly what your code is already doing, so it's a bit difficult to help you reliably with a single answer...

    So, you're inserting a section break: what kind? New Page or Continuous?

    A new section will inherit the settings from the previous section by default. So if you want different settings your code needs to adjust them after the section has been created. If you want all pages of the new section to reflect the non-first-page header/footer of the previous section then you need to DEactivate the Different First Page setting.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, October 5, 2015 5:22 PM
    Moderator
  • Sorry for the delayed reply, I have been snowed under with stuff and haven't managed to get onto here to reply until now.  So at current this is what i'm doing,

    I've removed a lot of code from this, but this creates my first page header and second page header and footer.

    dynamic pObjFirstSection = null;
    dynamic pObjActiveRange = null;
    dynamic pObjIntroSection = null;
    dynamic pObjMethodSection = null;
    
    Section pSecCoverPageSection = pLisOrderedSections[0];
    if(pSecCoverPageSection.Heading.LineType == Parser.LineType.heading1)
    {
    	//first page header
    	pObjFirstSection = pObjDoc.Sections.First;
    	pObjFirstSection.PageSetup.DifferentFirstPageHeaderFooter = -1; //true
    	dynamic pObjCoverPageHeader = pObjFirstSection.Headers.Item[2];
    	dynamic pObjCoverPageHeaderRange = pObjCoverPageHeader.Range;
    	//add header content here
    
    	//add a page break to the first page to take us onto the second page
    	pObjActiveRange = pObjFirstSection.Range;
    	pObjActiveRange.InsertBreak(7);
    	pObjIntroSection = pObjDoc.Sections.Add();
    
    	//all other headers
    	dynamic pObjPrimaryHeader = pObjIntroSection.Headers.Item[1];
    	dynamic pObjPrimaryHeaderRange = pObjPrimaryHeader.Range;
    	//add content to header here
    
    	//all other footer
    	dynamic pObjPrimaryFooter = pObjIntroSection.Footers.Item[1];
    	dynamic pObjPrimaryFooterRange = pObjPrimaryFooter.Range;
    	//add content to footer here
    }
    else
    {
    	throw new Exception("Markdown missing cover page heading.  It should be a level 1 heading.");
    }
    

    Now when I want my columned section I do this,

    pObjMethodSection = pObjDoc.Sections.Add();
    pObjMethodSection.PageSetup.DifferentFirstPageHeaderFooter = 0; //false
    pObjActiveRange = pObjMethodSection.Range;
    pObjActiveRange.PageSetup.TextColumns.Add();
    

    This creates the column section but it ends up with the first page header no matter what I do here, I've tried setting the section DifferentFirstPageHeaderFooter to True or False, neither do anything, but the second I try and modify the header contents it changes it on all first page / section headers.

    Complicated to explain I know...


    Somewhere out there...

    Tuesday, October 6, 2015 1:34 PM
  • Hi Firkinfedup,

    You could set the PageSetup.DifferentFirstPageHeaderFooter property to define if a different header or footer is used on the first page.

    Here is a simple code:

                Section sction = word.ActiveDocument.Sections[1];
                sction.PageSetup.DifferentFirstPageHeaderFooter = 0;

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    This didn't work for me unfortunately.  The new section header / footer still seems to be attached to the second section header / footer.

    Somewhere out there...

    Tuesday, October 6, 2015 1:36 PM
  • Hi Firk

    I THINK I'm following, although it's still not certain - it would be if you were using an older version of C# that would require you to pass all method parameters :-)

    My concern is your use of Sections.Add. The method has two optional parameters: the target range and the type of section break. You're not specifying either, so I'm guessing Word is making this a CONTINUOUS section break, not a NEW PAGE? Can you confirm that? (Continuous means the break can occur anywhere on a page; New Page means the break forces the section to start at the top of a (new) page.)

    The tricky thing with a continuous section break, especially if it (the columns) end on the same page it starts, is that you may never see the headers/footers for that section. You'll see them for the previous or the following section.

    Look at a document your code generates and observe Word's status bar as you click at the beginning, in the multiple columns and after the columns. At the left you should see Page # Section #. What section numbers (indexes) are you seeing? And if you look at (edit) the Headers and Footers they should also be labelled by section. Are you seeing the index number for the columns section?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, October 6, 2015 5:35 PM
    Moderator