Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Changing footers when concatenating documents programmatically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Lott - 24 Apr 2007 15:28 GMT
Using Word 2003, the interop assembly, and .net, I am concatenating documents
together.

In order to change the footer from say A-1 for appendix A, to the next B-1
for appendix B, I am having to change the page orientation and then change it
back after the new footer is accepted.

This is a workaround, does anyone know a better way.

Thanks

Code below

Public Sub AppendFile(ByVal StylePathandFile As String, ByVal
InputFileandName As String, ByVal PageBreakRequired As Boolean) Implements
rptAFERDInterfCore.IDescribeOutputFile.AppendFile
       'WES todo"
       'Convert the input into the doc file
       Dim localDocument As Word.Document = Nothing
       Dim NewSection As Word.Section
       Dim LastSection As Word.Section
       Dim a As Integer
       Dim b As Integer
       Dim c As Integer
       Dim Restart As Boolean
       Dim Same As Boolean

       mApplication.Selection.EndOf(CType(Word.WdUnits.wdStory, Object))

       Try
           localDocument =
CType(mApplication.Documents.Open(CType(InputFileandName, Object)),
Word.Document)

           ClearBeginningPageBreak(localDocument)

           NewSection = CType(localDocument.Sections(1), Word.Section)

           Restart =
NewSection.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection

       Catch ex As Exception

       Finally
           localDocument.Close(CType(False, Object))
       End Try

       If Restart And Not mFirst Then
           PageBreakRequired = False
       End If

       If PageBreakRequired Then
           mDocument.Activate()
           If Not HasAPageBreak(mDocument) Then
               
mApplication.Selection.InsertBreak(CType(Word.WdBreakType.wdSectionBreakNextPage, Object))
               mApplication.Selection.EndOf(CType(Word.WdUnits.wdStory,
Object))
           End If
       End If

       Try

           localDocument =
CType(mApplication.Documents.Open(CType(InputFileandName, Object)),
Word.Document)

           ClearBeginningPageBreak(localDocument)

           Try

               b = localDocument.Sections.Count

               For a = 1 To b

                   c = mDocument.Sections.Count

                   LastSection = CType(mDocument.Sections(c), Word.Section)

                   NewSection = CType(localDocument.Sections(a),
Word.Section)

                   If Restart And Not mFirst Then
                       If NewSection.PageSetup.Orientation =
Word.WdOrientation.wdOrientPortrait Then
                           NewSection.PageSetup.Orientation =
Word.WdOrientation.wdOrientLandscape
                       Else
                           NewSection.PageSetup.Orientation =
Word.WdOrientation.wdOrientPortrait
                       End If

                   End If

                   If PageBreakRequired Then
             
                   Else

                       Same = CompareSections(LastSection.PageSetup,
NewSection.PageSetup)

                       mDocument.Activate()
                       If Same Then
                           
mApplication.Selection.InsertBreak(CType(Word.WdBreakType.wdSectionBreakContinuous, Object))
                       Else
                           
mApplication.Selection.InsertBreak(CType(Word.WdBreakType.wdSectionBreakNextPage, Object))
                       End If
                   End If

                   NewSection.Range.Copy()

                   mDocument.Activate()

                   mApplication.Selection.EndOf(CType(Word.WdUnits.wdStory,
Object))

                   mApplication.Selection.Paste()

                   c = mDocument.Sections.Count

                   LastSection = mDocument.Sections(c)

                   
LastSection.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = Not Restart
                   
LastSection.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = Restart

                   If Restart And Not mFirst Then
                       If LastSection.PageSetup.Orientation =
Word.WdOrientation.wdOrientPortrait Then
                           LastSection.PageSetup.Orientation =
Word.WdOrientation.wdOrientLandscape
                       Else
                           LastSection.PageSetup.Orientation =
Word.WdOrientation.wdOrientPortrait
                       End If
                   End If
                   mFirst = False
               Next
Cindy M. - 26 Apr 2007 14:45 GMT
Hi =?Utf-8?B?Sm9obiBMb3R0?=,

> Using Word 2003, the interop assembly, and .net, I am concatenating documents
> together.
>  
> In order to change the footer from say A-1 for appendix A, to the next B-1
> for appendix B, I am having to change the page orientation and then change it
> back after the new footer is accepted.

What's the problem if you don't do this?

Have you considered using Word's built-in functionality for automatically
including "chapter" numbering with the page number?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
John Lott - 26 Apr 2007 19:00 GMT
This report consists of about 45 word documents. These documents comprise
about 4 chapters and 3 indexes. So in theory a single chapter could consists
of 1 to xx sub-documents.

> Using Word 2003, the interop assembly, and .net, I am concatenating documents
> together.
[quoted text clipped - 137 lines]
>                     mFirst = False
>                 Next
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.