A
androo...
I tried to write a simple macro that when fired (with the selection point
between two next page section breaks) would delete the header and footer for
the section but not for any sections before or after. However the result
seems to be almost random deletions or error messages. Amazingly, the
results I get are not the same if I run the macro compared with stepping
through it. Here is the draft code I used:
Sub delete_HF4()
'Header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.PreviousHeaderFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
'Footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.PreviousHeaderFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
'Main Doc
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
I then tried a different approach but got similar results. I found that
putting mgsBox's before and after some lines made the macro work (or at
least become predictable) so I wonder if things are not updating in time for
the next line of code??? Any help would be appreciated.
Thanks androooooooooo...............
p.s. I also tried this code
Selection.HeaderFooter.LinkToPrevious = Not
Selection.HeaderFooter.LinkToPrevious
p.p.s. below is my other clunky and unsuccessful approach
Sub deleteHF3()
Dim mySection As Long
mySection = Selection.Sections(1).Index 'Remember current section
'Header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'Enter
header on this page
Selection.HeaderFooter.LinkToPrevious = False 'Do not link to previous
section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst,
Count:=(mySection + 1), Name:="" 'Goto next section
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'Enter
header on this page
Selection.HeaderFooter.LinkToPrevious = False 'Do not link to previous
section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst,
Count:=(mySection), Name:="" 'Goto original section
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'Enter
header on this page
Selection.WholeStory 'Select entire header in this section
Selection.Delete Unit:=wdCharacter, Count:=1 'Delete entire header in
this section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
'Footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 'Enter
Footer on this page
Selection.HeaderFooter.LinkToPrevious = False 'Do not link to previous
section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst,
Count:=(mySection + 1), Name:="" 'Goto next section
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 'Enter
Footer on this page
Selection.HeaderFooter.LinkToPrevious = False 'Do not link to previous
section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst,
Count:=(mySection), Name:="" 'Goto original section
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 'Enter
header on this page
Selection.WholeStory 'Select entire header in this section
Selection.Delete Unit:=wdCharacter, Count:=1 'Delete entire header in
this section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
End Sub
between two next page section breaks) would delete the header and footer for
the section but not for any sections before or after. However the result
seems to be almost random deletions or error messages. Amazingly, the
results I get are not the same if I run the macro compared with stepping
through it. Here is the draft code I used:
Sub delete_HF4()
'Header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.PreviousHeaderFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
'Footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.PreviousHeaderFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
'Main Doc
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
I then tried a different approach but got similar results. I found that
putting mgsBox's before and after some lines made the macro work (or at
least become predictable) so I wonder if things are not updating in time for
the next line of code??? Any help would be appreciated.
Thanks androooooooooo...............
p.s. I also tried this code
Selection.HeaderFooter.LinkToPrevious = Not
Selection.HeaderFooter.LinkToPrevious
p.p.s. below is my other clunky and unsuccessful approach
Sub deleteHF3()
Dim mySection As Long
mySection = Selection.Sections(1).Index 'Remember current section
'Header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'Enter
header on this page
Selection.HeaderFooter.LinkToPrevious = False 'Do not link to previous
section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst,
Count:=(mySection + 1), Name:="" 'Goto next section
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'Enter
header on this page
Selection.HeaderFooter.LinkToPrevious = False 'Do not link to previous
section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst,
Count:=(mySection), Name:="" 'Goto original section
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'Enter
header on this page
Selection.WholeStory 'Select entire header in this section
Selection.Delete Unit:=wdCharacter, Count:=1 'Delete entire header in
this section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
'Footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 'Enter
Footer on this page
Selection.HeaderFooter.LinkToPrevious = False 'Do not link to previous
section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst,
Count:=(mySection + 1), Name:="" 'Goto next section
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 'Enter
Footer on this page
Selection.HeaderFooter.LinkToPrevious = False 'Do not link to previous
section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst,
Count:=(mySection), Name:="" 'Goto original section
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter 'Enter
header on this page
Selection.WholeStory 'Select entire header in this section
Selection.Delete Unit:=wdCharacter, Count:=1 'Delete entire header in
this section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'Exit header
to main document
End Sub