Charles
Thu Dec 15 10:17:17 CST 2005
Sorry, I don't know of any. Below is some code that I use in manipulating
headers and footers that may help you get started. I just use the help in
vba.
Private Sub ReplaceHeaders(sTemplateName As String)
' Altered to delete stories 8 October 2005
' Replaces Header and FirstPageHeader with contents from
' base template
' Replaces Footer and FirstPageFooter with contents from
' base template
' Assumes that bookmarks have been preserved in base and copies.
' Otherwise will generate error
' Required bookmarks are "Footer1," "Footer2," "Header1," and
"Header2"
'
Dim rRange As Range
Dim sFooter As String
Dim sHeader As String
'
' First Page Header
Set rRange = ActiveDocument.StoryRanges(wdFirstPageHeaderStory)
rRange.Delete
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:="Header1", _
ConfirmConversions:=False, Attachment:=False, Link:=False
' Continuation Header
Set rRange = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
rRange.Delete
rRange.Style = ActiveDocument.Styles("Header 3")
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:="Header2", _
ConfirmConversions:=False, Attachment:=False, Link:=False
' First Page Footer
Set rRange = ActiveDocument.StoryRanges(wdFirstPageFooterStory)
rRange.Delete
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:="Footer1", _
ConfirmConversions:=False, Attachment:=False, Link:=False
' Continuation Footer
Set rRange = ActiveDocument.StoryRanges(wdPrimaryFooterStory)
rRange.Delete
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:="Footer2", _
ConfirmConversions:=False, Attachment:=False, Link:=False
End Sub
--
Charles Kenyon
Word New User FAQ & Web Directory:
http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
http://addbalance.com/usersguide
See also the MVP FAQ:
http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
"rVo" <demo@vlaamsparlement.be> wrote in message
news:uIVDEFZAGHA.3976@TK2MSFTNGP09.phx.gbl...
> Dear Charles,
>
> Could you point me to an example (or some documentation) for this approach
> as I have no experience at all with it?
>
> Thanks for your intrest/help.
>
> rVo
>
> "Charles Kenyon" <msnewsgroup@remove.no.spam.addbalance.com> schreef in
> bericht news:u5oFv3YAGHA.2320@TK2MSFTNGP11.phx.gbl...
>> You are using the selection object rather than the range object. If you
> use
>> the range, you will get more consistent results and not need multiple
> pages
>> when your procedure is run.
>> --
>> Charles Kenyon
>>
>> Word New User FAQ & Web Directory:
http://addbalance.com/word
>>
>> Intermediate User's Guide to Microsoft Word (supplemented version of
>> Microsoft's Legal Users' Guide)
http://addbalance.com/usersguide
>>
>> See also the MVP FAQ:
http://word.mvps.org/FAQs/ which is awesome!
>> --------- --------- --------- --------- --------- ---------
>> This message is posted to a newsgroup. Please post replies
>> and questions to the newsgroup so that others can learn
>> from my ignorance and your wisdom.
>>
>> "rVo" <demo@vlaamsparlement.be> wrote in message
>> news:elQkGmYAGHA.3140@TK2MSFTNGP14.phx.gbl...
>> > Ok, below is some code that is supposed to put a header on page 1 of
>> > the
>> > document, leave the header of the second page blank
>> > Page 3&4 (and all following) should get mirrored headers.
>> >
>> > I have no control over headers which are already in the document; for
>> > testing purposes you need atleast 4 pages in a document.
>> >
>> > The result of the code below is never the same which made me guess that
>> > Word
>> > is encountering one of it's infamous timing-problems.
>> > The document on which I've tested this code is 400+ pages. Using
>> > Word2K3
>> > on
>> > Win2K on a very fast machine with 1GB of memory.
>> >
>> > I had to put a # on each line because I'm behind a very limitting
> firewall
>> > which won't let me send out code snippets otherwise.
>> > (the # can simply be removed with a text editor's find/replace option).
>> >
>> > I really hope it's not too shocking what I did here.
>> >
>> > Kind regards,
>> >
>> > rVo
>> >
>> >
>> > #Sub SetHeaders()
>> > # Selection.GoTo what:=wdGoToPage, which:=wdGoToFirst
>> > #
>> > # If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
>> > # ActiveWindow.Panes(2).Close
>> > # End If
>> > # If ActiveWindow.ActivePane.View.Type = wdNormalView Or
>> > ActiveWindow.ActivePane.View.Type = wdOutlineView Then
>> > # ActiveWindow.ActivePane.View.Type = wdPrintView
>> > # End If
>> > #
>> > # 'Make sure that the first header is empty
>> > # '---------------------------------------------------------------
>> > # ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
>> > # Selection.WholeStory
>> > # Selection.Delete
>> > #
>> > # 'Make header of first page
>> > # '---------------------------------------------------------------
>> > # With Selection.PageSetup
>> > # .OddAndEvenPagesHeaderFooter = False
>> > # .DifferentFirstPageHeaderFooter = False
>> > # End With
>> > # Selection.Tables.Add Range:=Selection.Range, NumRows:=1,
>> > NumColumns:=1,
>> > DefaultTableBehavior:=wdWord9TableBehavior,
>> > AutoFitBehavior:=wdAutoFitFixed
>> > # With Selection.Tables(1)
>> > # If .Style <> "Tabelraster" Then
>> > # .Style = "Tabelraster"
>> > # End If
>> > # .ApplyStyleHeadingRows = True
>> > # .ApplyStyleLastRow = True
>> > # .ApplyStyleFirstColumn = True
>> > # .ApplyStyleLastColumn = True
>> > # End With
>> > #
>> > # With Selection.Range.Cells(1)
>> > # .PreferredWidthType = wdPreferredWidthPoints
>> > # .PreferredWidth = 100
>> > # End With
>> > # Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
>> > # Selection.Font.Bold = True
>> > # Selection.TypeText "Some text"
>> >
>> > # 'Clear header for second page
>> > # '---------------------------------------------------------------
>> > # ActiveWindow.ActivePane.View.NextHeaderFooter
>> > # Selection.WholeStory
>> > # Selection.Delete
>> > #
>> > # 'Clear header for third page
>> > # '---------------------------------------------------------------
>> > # ActiveWindow.ActivePane.View.NextHeaderFooter
>> > # Selection.HeaderFooter.LinkToPrevious = False
>> > # Selection.WholeStory
>> > # Selection.Delete
>> > # Selection.HeaderFooter.LinkToPrevious = False
>> > #
>> > # 'fill header for third page
>> > # '---------------------------------------------------------------
>> > # Selection.Tables.Add Range:=Selection.Range, NumRows:=1,
>> > NumColumns:=3,
>> > DefaultTableBehavior:=wdWord9TableBehavior,
>> > AutoFitBehavior:=wdAutoFitFixed
>> > #
>> > # Selection.MoveRight unit:=wdCell, Count:=1
>> > # Selection.Range.Cells(1).PreferredWidthType =
> wdPreferredWidthPercent
>> > # Selection.Range.Cells(1).PreferredWidth = 10
>> > #
>> > # Selection.MoveRight unit:=wdCell, Count:=1
>> > # Selection.Range.Cells(1).PreferredWidthType =
> wdPreferredWidthPercent
>> > # Selection.Range.Cells(1).PreferredWidth = 8
>> > #
>> > # Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
>> > # Selection.TypeText "-"
>> > # Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
>> > # Selection.TypeText "-"
>> > #
>> > # Selection.MoveLeft unit:=wdCell, Count:=1
>> > # With Selection.Cells
>> > # With .Borders(wdBorderLeft)
>> > # .LineStyle = wdLineStyleSingle
>> > # .LineWidth = wdLineWidth050pt
>> > # .Color = wdColorAutomatic
>> > # End With
>> > # With .Borders(wdBorderRight)
>> > # .LineStyle = wdLineStyleSingle
>> > # .LineWidth = wdLineWidth050pt
>> > # .Color = wdColorAutomatic
>> > # End With
>> > # .Borders(wdBorderTop).LineStyle = wdLineStyleNone
>> > # .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
>> > # .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
>> > # .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
>> > # .Borders.Shadow = False
>> > # End With
>> > #
>> > # With Options
>> > # .DefaultBorderLineStyle = wdLineStyleSingle
>> > # .DefaultBorderLineWidth = wdLineWidth050pt
>> > # .DefaultBorderColor = wdColorAutomatic
>> > # End With
>> > #
>> > # Selection.MoveLeft unit:=wdCell, Count:=1
>> > # Selection.Range.Cells(1).PreferredWidthType =
> wdPreferredWidthPercent
>> > # Selection.Range.Cells(1).PreferredWidth = 65
>> > #
>> > # Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
>> > # Selection.TypeText Text:="Some other text"
>> > #
>> > # With Selection.HeaderFooter.PageNumbers
>> > # .RestartNumberingAtSection = True
>> > # .StartingNumber = 1
>> > # End With
>> > #
>> > # 'clear header for fourth page
>> > #
>> >
> '-------------------------------------------------------------------------
>> > # ActiveWindow.ActivePane.View.NextHeaderFooter
>> > # Selection.HeaderFooter.LinkToPrevious = False
>> > # Selection.WholeStory
>> > # Selection.Delete
>> > # Selection.HeaderFooter.LinkToPrevious = False 'twice because once
>> > doesn't seem to work
>> > #
>> > # 'fill header for fourth page
>> > #
>> >
> '-------------------------------------------------------------------------
>> > #
>> > # Selection.Tables.Add Range:=Selection.Range, NumRows:=1,
>> > NumColumns:=3,
>> > DefaultTableBehavior:=wdWord9TableBehavior,
>> > AutoFitBehavior:=wdAutoFitFixed
>> > #
>> > # With Selection.Tables(1)
>> > # If .Style <> "Tabelraster" Then
>> > # .Style = "Tabelraster"
>> > # End If
>> > # .ApplyStyleHeadingRows = True
>> > # .ApplyStyleLastRow = True
>> > # .ApplyStyleFirstColumn = True
>> > # .ApplyStyleLastColumn = True
>> > # End With
>> > #
>> > # With Selection.Range.Cells(1)
>> > # .PreferredWidthType = wdPreferredWidthPercent
>> > # .PreferredWidth = 8
>> > # End With
>> > #
>> > # Selection.MoveRight unit:=wdCell, Count:=1
>> > # Selection.Range.Cells(1).PreferredWidthType =
> wdPreferredWidthPercent
>> > # Selection.Range.Cells(1).PreferredWidth = 17
>> > # Selection.MoveRight unit:=wdCell, Count:=1
>> > # Selection.Range.Cells(1).PreferredWidthType =
> wdPreferredWidthPercent
>> > # Selection.Range.Cells(1).PreferredWidth = 75
>> > #
>> > # Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
>> > # Selection.TypeText Text:="Again some text"
>> > # Selection.MoveLeft unit:=wdCell, Count:=1
>> > #
>> > # With Selection.Cells
>> > # With .Borders(wdBorderLeft)
>> > # .LineStyle = wdLineStyleSingle
>> > # .LineWidth = wdLineWidth050pt
>> > # .Color = wdColorAutomatic
>> > # End With
>> > # With .Borders(wdBorderRight)
>> > # .LineStyle = wdLineStyleSingle
>> > # .LineWidth = wdLineWidth050pt
>> > # .Color = wdColorAutomatic
>> > # End With
>> > # .Borders(wdBorderTop).LineStyle = wdLineStyleNone
>> > # .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
>> > # .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
>> > # .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
>> > # .Borders.Shadow = False
>> > # End With
>> > #
>> > # With Options
>> > # .DefaultBorderLineStyle = wdLineStyleSingle
>> > # .DefaultBorderLineWidth = wdLineWidth050pt
>> > # .DefaultBorderColor = wdColorAutomatic
>> > # End With
>> > #
>> > # Selection.MoveLeft unit:=wdCell, Count:=1
>> > # Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
>> > # Selection.TypeText "-"
>> > # Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
>> > # Selection.TypeText "-"
>> > #
>> >
>> >
>> > # 'Extreme Brutal way to link all following headers to the previous
>> > ones
>> > (I know)
>> > # '--------------------------------------------------------------
>> > # On Error GoTo yourDone
>> > # Do While 1 = 1
>> > # ActiveWindow.ActivePane.View.NextHeaderFooter
>> > # Selection.HeaderFooter.LinkToPrevious = True
>> > # Loop
>> > #yourDone:
>> > # On Error GoTo 0
>> > #
>> > # 'Ending
>> > # '---------------------------------------------------------------
>> > # ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>> >
>> > # Selection.GoTo what:=wdGoToPage, which:=wdGoToFirst
>> > # On Error Resume Next
>> > # ActiveDocument.Fields(1).Update 'this is the TOC in my
>> > document
>> > # On Error GoTo 0
>> > #End Sub
>> >
>> >
>>
>>
>
>