![]() |
|
|
|
#1
|
|||
|
|||
|
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
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 |
|
#2
|
||||
|
||||
|
There is no need to set the View.Type or use SeekView for what you're doing. Try:
Code:
Dim fg As Field
With WordDoc
.Sections(2).Headers(wdHeaderFooterPrimary).LinkToPrevious = False
With .Sections(1).Headers(wdHeaderFooterPrimary).Range
For Each fg In .Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields
If (InStr(1, fg.Code.text, "{ORDERNR}") > 0) Then
fg.Code.Text = Replace(fg.Code.Text, "{ORDERNR}", "{FONR}")
fg.Update
End If
Next fg
End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
||||
|
||||
|
Cross-posted at: https://social.msdn.microsoft.com/Fo...?forum=worddev
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| 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 |
Section Break (Next Page) replaces Section Break (Continuous) when deleted
|
Carlabasson | Word | 2 | 03-25-2013 10:13 PM |
Section Break changes formatting on next Header 1
|
Eastendr | Word | 1 | 01-21-2013 05:57 AM |
Help! Section Page Break Not Working - Need new Header and Footers
|
dkgolfer16 | Word | 2 | 05-23-2012 11:02 AM |
Header after page break
|
mashtonsmith | Word | 1 | 03-11-2011 10:21 AM |