Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 653

VBA MS Word - Delete all headers not footers

$
0
0

I am facing an issue where I am trying to delete all the headers, but I am deleting the footers as well. I am using WDHeaderFooterPrimary, but the footer is still being deleted. I have moved all the sections to the end of the page for future work on the document.

' remove all sections    For i = doc.Sections.Count To 5 Step -1          With doc.Sections(i).Range.Find               .ClearFormatting               .Text = "^b"               .Replacement.ClearFormatting               .Replacement.Text = ""               .Execute Replace:=wdReplaceAll          End With    Next'insert section after each page     For i = 5 To doc.ComputeStatistics(wdStatisticPages)          Selection.GoTo What:=wdGoToPage, Which:=wdGoToLast, Count:=i          Selection.InsertBreak Type:=wdSectionBreakContinuous     Next' delete shapes     For i = 5 To doc.Sections.Count          Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=i          Set hdr = doc.Sections(i).Headers(wdHeaderFooterPrimary)               For Each shp In hdr.Shapes                    shp.Delete               Next     Next

How do I remove just the headers?


Viewing all articles
Browse latest Browse all 653

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>