This is giving me headaches.
I have a Word macro that is pretty huge.
And at a certain point I have to change the header and format of the pages.
Hence I insert a break at this point
Selection.InsertBreak Type:=wdSectionBreakContinuous
change to landscape/horizontal format (cause the images have also this format)
WordBasic.TogglePortrait Tab:=3, PaperSize:=0, TopMargin:="2.5", _
BottomMargin:="2.5", LeftMargin:="2", RightMargin:="2.5", Gutter:="0", _
PageWidth:="29.7", PageHeight:="21", Orientation:=1, FirstPage:=0, _
OtherPages:=0, VertAlign:=0, ApplyPropsTo:=0, FacingPages:=0, _
HeaderDistance:="1.25", FooterDistance:="1.25", SectionStart:=0, _
OddAndEvenPages:=0, DifferentFirstPage:=0, Endnotes:=0, LineNum:=0, _
StartingNum:=1, FromText:=wdAutoPosition, CountBy:=0, NumMode:=0, _
TwoOnOne:=0, GutterPosition:=0, LayoutMode:=0, CharsLine:=41, LinesPage:= _
39, CharPitch:=220, LinePitch:=360, DocFontName:="+Textkörper", _
DocFontSize:=11, PageColumns:=1, TextFlow:=0, FirstPageOnLeft:=0, _
SectionType:=1, FolioPrint:=0, ReverseFolio:=0, FolioPages:=1
enter the header
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
the pages before shouldn’t be changed so unlink the header formation with the previous
Selection.HeaderFooter.LinkToPrevious = False
Jump out of the header go to the last page = the first page of the new section
This needs to be done otherwise I am in the header of the previous section due to the above command. (Dont know why it jumps into the last header) and jump into the correct header
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.EndKey unit:=wdStory
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Select the whole header and delete it
Selection.WholeStory
Selection.Delete
Everything works fine if i set a breakpoint after changing to horizontal format means first time I jump into the header or at an earlier point of the above listed. But this is the last possible one.
Without the breakpoint instead of deleting only the header of the last page also the headers of the previous section are deleted.
I don’t know why this happens or how to prevent it.
Ok I figured out how to do it.
I already thought that it has something to do with the runtime and that some events couldn’t be executed in time.
so i wrote a loop with doevents
This is too much I know but it works 😉
edit:
Actually 2 times is enough no need for 1000000 I just wanted to be sure in the beginning 😀