The following VB Code does not work correctly. It bombs out at the
"ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader" line.
I don't have any experience in coding. Would anyone know why this is failing?
Thanks in advance
--------------------------
Sub AutoNew()
Selection.HomeKey Unit:=wdStory
Selection.WholeStory
Selection.Fields.Update
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Or
ActiveWindow.ActivePane.View.Type _
= wdMasterView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.WholeStory
Selection.Fields.Update
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.HomeKey Unit:=wdStory
End Sub
------------------------------
Charles Kenyon - 22 Nov 2005 20:21 GMT
Don't know what is going wrong, but using the selection object (which you
get from recording) is a mistake. Your code will miss headers and footers
even if it works if there are multiple sections or different kinds. Try:
Sub FieldsUpdateAllStory()
' All Story Field Updater
' Written by Charles Kyle Kenyon 9 December 2004
' repaired with help from Jezebel 10 December 2004
' Note, if used in protected form this will reset
' formfields to their defaults
Dim oStory As Range
On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
Do
oStory.Fields.Update
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next
End Sub

Signature
Charles Kenyon
Word New User FAQ & Web Directory: http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide
See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
> The following VB Code does not work correctly. It bombs out at the
> "ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader" line.
[quoted text clipped - 32 lines]
> End Sub
> ------------------------------
Doug Robbins - Word MVP - 22 Nov 2005 20:41 GMT
Most fields in a document can be updated simply by using
With ActiveDocument
.PrintPreview
.Close PrintPreview
End with
Or, if that doesn't do the trick, use:
With ActiveDocument
.Range.Fields.Update
For i = 1 To .Sections.Count
.Sections(i).Headers(wdHeaderFooterFirstPage).Range.Fields.Update
.Sections(i).Headers(wdHeaderFooterPrimary).Range.Fields.Update
.Sections(i).Footers(wdHeaderFooterFirstPage).Range.Fields.Update
.Sections(i).Footers(wdHeaderFooterPrimary).Range.Fields.Update
Next i
End With

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> The following VB Code does not work correctly. It bombs out at the
> "ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader" line.
[quoted text clipped - 32 lines]
> End Sub
> ------------------------------