General information
Category:
COM/DCOM and OLE Automation
Try to use .ActiveDocument.Sections(i) approach instead. Like:
with .ActiveDocument.Sections(1)
.Headers(wdHeaderFooterPrimary).Range.Text = "Header1 text"
.Footers(wdHeaderFooterPrimary).Range.Text = "Footer1 text"
endwith
with .ActiveDocument.Sections(2)
.Headers(wdHeaderFooterPrimary).Range.Text = "Header2 text"
.Footers(wdHeaderFooterPrimary).Range.Text = "Footer2 text"
endwith
>I am working on a large project involving word automation. Due to the lack of documentation of this concept, I am inching along. Maybe someone can help me with this.
>
>I wish to have various sections with different headers / footers in each.
>
>This code is an example of how I am attempting to do this. However, it is not working as expected. Even though I am setting the property LINKTOPREVIOUS as .F.
>
>Any ideas would be appreciated.
>
>
>
>oRange.InsertBreak(wdSectionBreakNextPage)
>
>* Begin Page 4
>* Introduction Letter
>oRange.Collapse(wdCollapseEnd)
>
>FOR j = 1 TO 5
> oRange.InsertAfter(CR)
>endfor
>oRange.InsertAfter(DTOC(DATE()))
>oRange.InsertAfter(CR+CR)
>oRange.InsertAfter("To the Management of ")
>oRange.Font.Name = FONT_NAME_STANDARD
>oRange.Font.Bold = 0
>oRange.Font.Italic = 0
>oRange.Font.Size = FONT_SIZE_STANDARD
>oRange.ParagraphFormat.Alignment = wdAlignParagraphLeft
>oRange.Collapse(wdCollapseEnd)
>
>* Here is where I attempt to change the text for this particular
>* section's header/footer. The Text I "Insert" becomes part of the
>* text that was in the previous section's header/footer.
>
>oHeader = oDoc.Sections.Last.Headers[WdHeaderFooterPrimary]
>oHeader.LinkToPrevious = .F.
>oHeader.Range.InsertAfter("New Header")
>
>oFooter = oDoc.Sections.Last.Footers[WdHeaderFooterPrimary]
>oFooter.LinkToPrevious = .F.
>oFooter.Range.InsertAfter("New Footer")
>
>oRange.Collapse(wdCollapseEnd)
>* End Page 4
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only