Macro breaks but works when breakpoint used

M

Mark

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
 
J

Jonathan West

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.
 

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