J
John Lott
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
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