Job Lot

I need a different first page in my word document. First page should have image in the header and a line across the page in the footer. I am using the following code but it does not show me the line on the first page. When I press Ctrl + Enter to create a new page it shows the line on the new page. If I change the code to show some image in the footer instead of a line it works alrite. What is going wrong here please help!!!

Thanks

PageSetup.DifferentFirstPageHeaderFooter = -1;

Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage].Shapes.AddPicture(@"C:\Image\abc.jpg", ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage].Shapes.AddLine(35f, 500f, 400, 500f, ref missing);




Re: Visual Studio Tools for Office Issue creating different first page in word doc

Ji Zhou – MSFT

Hi,

I can reproduce your issue. After testing, I find it seems that the codes insert the line to wdHeaderFooterPrimary, but not wdHeaderFooterFirstPage. But when we insert a picture or text, it works OK! Yeah, it is really weird!

But at right now, I think you can use the following codes as a workaround to avoid the problem.

Code Block

this.Application.ActiveDocument.Sections.First.PageSetup.DifferentFirstPageHeaderFooter = -1;

//Edit the Header

this.Application.CommandBars["Header Area Popup"].Controls["Edit &Header"].Execute();

this.Application.Selection.InlineShapes.AddPicture(@"C:\test.jpg", ref missing, ref missing, ref missing);

this.Application.CommandBars["Header and Footer"].Controls["&Close"].Execute();

//Edit the Footer

this.Application.CommandBars["Footer Area Popup"].Controls["&Edit Footer"].Execute();

Word.InlineShape line = this.Application.Selection.InlineShapes.AddHorizontalLineStandard(ref missing);

this.Application.CommandBars["Header and Footer"].Controls["&Close"].Execute();

Hope this can help more or less!

Thanks

Ji






Re: Visual Studio Tools for Office Issue creating different first page in word doc

Job Lot

Hi Ji

Thanks for spending time on investigating this. I can't use inline shapes as I have run the line across the page and inline shape in footer will be relative to the width of the footer. This is what it did to over come the issue.

Code Block

// Change view to the current footer.

wordDocument.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekFirstPageFooter;

// Change selection to the footer.

currentSelection = wordDocument.ActiveWindow.Selection;

// Add a line to the footer.

returnValue =

wordDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage]

.Shapes.AddLine(25f, 780f, 570f, 780f, ref missing);

// Change view to the main document.

wordDocument.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;

currentSelection = wordDocument.ActiveWindow.Selection;