Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Headers & Section Numbers (VBA/Word/2003)

    Using code I :

    <UL><LI>create a new document,
    <LI>insert a number of Section Breaks (Next Page); the number is determined by other factors, then
    <LI>I attempt to disconnect all headers from the previous header with the following code.[/list]<pre> Set oDoc = Documents(Target)
    With oDoc

    ' Insert the appropriate number of section breaks and
    ' ensure we're in Page view done here

    Selection.HomeKey wdStory
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    For i = 1 To .Sections.Count - 1
    ActiveWindow.ActivePane.View.NextHeaderFooter
    Selection.HeaderFooter.LinkToPrevious = False
    Next i
    </pre>



    However with the above code the last section is never reached. In debugging and trying alternative approaches I discovered that if the insertion point is in the header of section n , command "Selection.HeaderFooter.LinkToPrevious = False" the causes the property of Selection.Information(wdActiveEndSectionNumber) to return n-1
    I was able to achieve the desired results by using the following code, but fail to understand what was going on in the first example. Any guidance will be greatly appreciated.
    <pre> Set oDoc = Documents(Target)
    With oDoc

    ' Insert the appropriate number of section breaks and
    ' ensure we're in Page view done here



    Selection.HomeKey wdStory
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    LastSect = False
    Do
    ActiveWindow.ActivePane.View.NextHeaderFooter
    If Selection.Information(wdActiveEndSectionNumber) _
    = .Sections.Count Then LastSect = True
    Selection.HeaderFooter.LinkToPrevious = False
    Loop While Not LastSect
    </pre>

    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Headers & Section Numbers (VBA/Word/2003)

    I haven't tried to test your code, but it isn't necessary to switch to header/footer view to modify headers:

    Dim i As Integer
    Dim oHdr As HeaderFooter
    For i = 2 To oDoc.Sections.Count
    For Each oHdr In oDoc.Sections(i).Headers
    oHdr.LinkToPrevious = False
    Next oHdr
    Next i

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Headers & Section Numbers (VBA/Word/2003)

    We never correspond but what I learn. Thank you Sir.
    Regards
    Don

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •