From: Terry Aney on 25 Feb 2010 15:50 Hi, I am automating Word 2007 (have tried with VBA and C#) to append several documents together. These documents can have different margins, headers/footers, etc. I have followed the procedure described by http://word.mvps.org/faqs/Formatting/WorkWithSections.htm and am not getting the desired output. Given the following documents: Document 1 - No headers, footers without page numbers Document 2 - Different margins from Document 1, has no headers, but has footers without page numbers. Document 3 - Same margins as Document 2, has no headers, but has footers *with* page numbers. The first section in this document is *not* linked to previous section (or so Word says when I have this document opened in isolation) and it has its page numbering set to restart at number 1. I have a loop that essentially puts the continuous section breaks at the beginning and end (setting size to 1 font size so 'not noticeable') in via code 'simliar' to: foreach document call application.Selection.HomeKey(wdStory) call application.Selection.InsertBreak(wdSectionBreakContinuous) call application.Selection.Document.Sections(1).Range.Select application.Selection.Font.Size = 1 call application.Selection.EndKey(wdStory) call application.Selection.InsertBreak(wdSectionBreakContinuous) call application.Selection.Document.Sections( application.Selection.Document.Sections.Count-1 ).Range.Characters.Last.Select application.Selection.Font.Size = 1 Then assuming I've opened Document 1, I have the following code to merge the three documents: call application.Selection.EndKey(wdStory) call application.Selection.InsertBreak(wdSectionBreakNextPage) call application.Selection.InsertFile("Document 2") call application.Selection.EndKey(wdStory) call application.Selection.InsertBreak(wdSectionBreakNextPage) call application.Selection.InsertFile("Document 3") Everything (i.e. margins, headers and footers) looks pretty good except for the problem that the *first page* of 'Document 3' has a page number equal to the actual page that the page corresponds to in *entire* merge (i.e. page 13 say), then the *second page* of 'Document 3' starts over at page number 2 and continues on. When I examine the page numbering restart properties on the first page of 'Document 3' (after the merge) the property has changed to 'Continue from previous section'. If anyone has any suggestions I would greatly appreciate it.
From: Doug Robbins - Word MVP on 25 Feb 2010 20:04 The following code will set the page numbering in each section of a document to start at 1: Dim s As Section For Each s In ActiveDocument.Sections With s.Headers(wdHeaderFooterPrimary).PageNumbers .RestartNumberingAtSection = True .StartingNumber = 1 End With Next s -- Hope this helps, Doug Robbins - Word MVP Please reply only to the newsgroups unless you wish to obtain my services on a paid professional basis. "Terry Aney" <TerryAney(a)discussions.microsoft.com> wrote in message news:6F0932B4-1CAA-4EC6-903C-AD36AD04ED7E(a)microsoft.com... > Hi, > > I am automating Word 2007 (have tried with VBA and C#) to append several > documents together. These documents can have different margins, > headers/footers, etc. > > I have followed the procedure described by > http://word.mvps.org/faqs/Formatting/WorkWithSections.htm and am not > getting > the desired output. > > Given the following documents: > > Document 1 - No headers, footers without page numbers > > Document 2 - Different margins from Document 1, has no headers, but has > footers without page numbers. > > Document 3 - Same margins as Document 2, has no headers, but has footers > *with* page numbers. The first section in this document is *not* linked > to > previous section (or so Word says when I have this document opened in > isolation) and it has its page numbering set to restart at number 1. > > I have a loop that essentially puts the continuous section breaks at the > beginning and end (setting size to 1 font size so 'not noticeable') in via > code 'simliar' to: > > foreach document > call application.Selection.HomeKey(wdStory) > call application.Selection.InsertBreak(wdSectionBreakContinuous) > call application.Selection.Document.Sections(1).Range.Select > application.Selection.Font.Size = 1 > > call application.Selection.EndKey(wdStory) > call application.Selection.InsertBreak(wdSectionBreakContinuous) > call application.Selection.Document.Sections( > application.Selection.Document.Sections.Count-1 > ).Range.Characters.Last.Select > application.Selection.Font.Size = 1 > > Then assuming I've opened Document 1, I have the following code to merge > the > three documents: > > call application.Selection.EndKey(wdStory) > call application.Selection.InsertBreak(wdSectionBreakNextPage) > call application.Selection.InsertFile("Document 2") > call application.Selection.EndKey(wdStory) > call application.Selection.InsertBreak(wdSectionBreakNextPage) > call application.Selection.InsertFile("Document 3") > > Everything (i.e. margins, headers and footers) looks pretty good except > for > the problem that the *first page* of 'Document 3' has a page number equal > to > the actual page that the page corresponds to in *entire* merge (i.e. page > 13 > say), then the *second page* of 'Document 3' starts over at page number 2 > and > continues on. > > When I examine the page numbering restart properties on the first page of > 'Document 3' (after the merge) the property has changed to 'Continue from > previous section'. > > If anyone has any suggestions I would greatly appreciate it.
|
Pages: 1 Prev: Making a macro "auto open" Next: Word 2007 VBA Tables & Dates |