Run-time error '4605'

M

Me

I recently inherited a Word file at work and I'm getting this error on an
auto run macro. Since I don't know anything about VB programming, I was
wondering if somewone could tell me how to fix this problem. This error
prevents me from using this file.

The code is:

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

Can anybody help me with this?

Thanks.
 
D

Doug Robbins

If you click on Debug when the error occurs, what line of code is
highlighted.

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

Me

D'oh! That certainly would help wouldn't it. ;-)

ActiveWindow.ActivePane.View.NextHeaderFooter


Thanks!
 
J

Jezebel

All the macro is doing is updating fields in the document, using a very
cludgy method. The error is coming up because the macro assumes that the
document has two sections, which I guess it doesn't. Quickest fix for you is
just to delete the whole macro and update fields manually. Or insert, as the
first line of code --

On error resume next

This is not a recommended practice in general (it's telling VBA to ignore
all errors) but it's OK in this case because the errors are not harmful.
 
D

Doug Robbins

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

Me

This worked perfectly.

I used this because it's only one line of code opposed to four lines that
Doug suggested.

Thanks guys!
 
D

Doug Robbins

My four lines would do the same as everything else that you had and the bad
practice of using On error resume next would not be needed.

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