Sub AutoNew Question

M

Me

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
------------------------------
 
C

Charles Kenyon

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
--
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


--------- --------- --------- --------- --------- ---------
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.
 
D

Doug Robbins - Word MVP

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

--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top