Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Sub AutoNew Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Me - 22 Nov 2005 18:30 GMT
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
> ------------------------------

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.