I'm pulling my hair out on this one. I've got a document
w/ several protected sections. In the event that the text
in one of the unprotected sections is accidently deleted,
I've written a macro to replace the text and tag it with
some required character and paragraph styles.

Here's the catch: when I execute the macro, I get a
Runtime error 4605 - "This method or property is not
available because the object refers to a protected area of
the document."

Yet, when I set a breakpoint on and step through
the "Selection.Style = ActiveDocument.Styles" line, it all
works as expected.

Here's all i'm trying to do:

Selection.MoveRight unit:=wdCharacter, Count:=17,
Extend:=wdExtend
Selection.Style = ActiveDocument.Styles
("IntelinkSummaryTitle")
Selection.MoveRight unit:=wdCharacter, Count:=7

Re: Macro breaks but works when breakpoint used by Jonathan

Jonathan
Thu Nov 06 04:20:24 CST 2003

Hi Mark,

If it works when stepping through but not when running, then something is
getting out of sync in the macro, probably between the document and the
screen display of it.

Try putting a couple of DoEvents commands immediately before the offending
line of code, so that Windows is given a chance to catch up with what the
macro has done.

--
Regards
Jonathan West - Word MVP
http://www.multilinker.com
Please reply to the newsgroup


"Mark" <mark_@_xsystems.com> wrote in message
news:00f901c3a3be$53c7e9b0$a301280a@phx.gbl...
> I'm pulling my hair out on this one. I've got a document
> w/ several protected sections. In the event that the text
> in one of the unprotected sections is accidently deleted,
> I've written a macro to replace the text and tag it with
> some required character and paragraph styles.
>
> Here's the catch: when I execute the macro, I get a
> Runtime error 4605 - "This method or property is not
> available because the object refers to a protected area of
> the document."
>
> Yet, when I set a breakpoint on and step through
> the "Selection.Style = ActiveDocument.Styles" line, it all
> works as expected.
>
> Here's all i'm trying to do:
>
> Selection.MoveRight unit:=wdCharacter, Count:=17,
> Extend:=wdExtend
> Selection.Style = ActiveDocument.Styles
> ("IntelinkSummaryTitle")
> Selection.MoveRight unit:=wdCharacter, Count:=7