Word Macro Question

M

Me

When I open a previously saved file and cancel options to enter a new number
and form name, a debugging error message comes up (Run-time error ‘4605’).
When the "end" option within that dialog box is selected, my cursor is placed
within the header instead of in the document, and when I close out of the
header/footer toolbar, I’m taken back to the document, but the entire
document is selected instead of me simply being within a certain cell or row.

This debugging error does not happen when the form is being created as
normal; this is only an issue when previously saved forms are opened to be
edited.

When the "debug" option within that dialog box is selected, I am taken into
the Visual Basic editor and show the following macro:

* * * * * *
Sub AutoOpen()

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

The macro bombs out at “ActiveWindow.ActivePane.View.NextHeaderFooter.â€

I am not familiar with VB coding, so that’s why I’m asking assistance here.

Any help would be greatly appreciated.

Thanks in advance.

Me
 
T

Tony Jollans

Hi Me!

Your problem is caused by the document only having one header and the code
trying to jump to the second header.

I don't know what your Forms are normally like or whether the code is
reasonable in the circumstances but adding an error trap (the outdented
lines below) should give a quick fix to make it run to the end,

......

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
On Error resume next
ActiveWindow.ActivePane.View.NextHeaderFooter

If err.number = 0 then
on error goto 0
Selection.WholeStory
Selection.Fields.Update
End iF
on error goto 0
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.HomeKey Unit:=wdStory

End Sub
 
D

Doug Robbins - Word MVP

Just use

With ActiveDocument
.PrintPreview
.ClosePrintPreview
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

Similar Threads


Top