Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-22-2016, 09:17 AM
jojo77 jojo77 is offline Touching Header range with VBA forces a page break Windows 10 Touching Header range with VBA forces a page break Office 2013
Novice
Touching Header range with VBA forces a page break
 
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
 

Tags
vba word headers



Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Break is adding Blank Page when Break occurs JoannL54 Word 3 07-01-2016 05:58 AM
Touching Header range with VBA forces a page break Section Break (Next Page) replaces Section Break (Continuous) when deleted Carlabasson Word 2 03-25-2013 10:13 PM
Touching Header range with VBA forces a page break Section Break changes formatting on next Header 1 Eastendr Word 1 01-21-2013 05:57 AM
Touching Header range with VBA forces a page break Help! Section Page Break Not Working - Need new Header and Footers dkgolfer16 Word 2 05-23-2012 11:02 AM
Touching Header range with VBA forces a page break Header after page break mashtonsmith Word 1 03-11-2011 10:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft