View Single Post
 
Old 11-22-2016, 09:17 AM
jojo77 jojo77 is offline Windows 10 Office 2013
Novice
 
Join Date: Nov 2016
Posts: 1
jojo77 is on a distinguished road
Default Touching Header range with VBA forces a page break

I have a script to modify a field in a document header:
Code:
WordDoc.ActiveWindow.View.Type = wdPrintView
                WordDoc.ActiveWindow.ActivePane.View.SeekView = 9
		WordDoc.Sections(2).Headers(wdHeaderFooterPrimary).LinkToPrevious = False
                WordDoc.ActiveWindow.ActivePane.View.SeekView = 0

                Dim fg As Field
                For Each fg In WordDoc.Sections(1).Headers(1).Range.Fields
                  If (InStr(1, fg.Code.text, "{ORDERNR}") > 0) Then
                     fg.Code.text = Replace(fg.Code.text, "{ORDERNR}", "{FONR}")
   		  End If
                Next fg
When I run this it causes a 4 page document to push down the last line to the next page (and since a hard page break has been put, the second page is then empty)

Now for the funny part.
After the VBA has run, double clicking on the header and then double clicking back on the document body, this resets the pages to their original state.

I have removed line by line and it turns out that to provoke the error it is enough to even have a reference to the Headers(1).Range, without even modifying the content.

When I have had similar issues I have forced a refresh by swithcing the view to the header and then back (similar to what I did with the double clicking), but for this problem it doesn't help.

Any ideas how to approach this problem to find a solution?

This is a Windows Server 2008 R2 installation accessed over Citrix
Office 15.0.4859.1001
Reply With Quote