MoveUntil method hangs

M

MikeT

Hello,

I have a macro that causes Word to hang when the macro is run in a document
that contains comments (the comment "bubbles"). In my macro, I use the
Selection.MoveUntil method and pass in a negative number or the wdBackward
constant. If the current selection is in front of a comment, MoveUntil hangs
word if I try to "back up" over the comment.

Here is a simple macro that shows the problem:

Public Sub GoToPrevStar()
Selection.MoveUntil "*", wdBackward
End Sub

Here is an example of a simple document that can be used to reproduce the
problem:
"The * [insert comment here]quick brown fox"

If I place my cursor after the comment (for example, between quick and
brown) and run the GoToPrevStar macro, Word hangs. If I take out the comment,
the macro works fine.

I have tested this in Word 2003 and Word 2002 and it hangs in both versions.

Has anyone heard of this problem or a workaround?

Thanks,
Mike
 
J

Jezebel

Hard to suggest a work-around without knowing what you're actually trying to
do; but in general the answer is: don't use the Selection object. It's never
necessary, and there are always better ways.
 
M

MikeT

What I'm trying to do is check to see if the cursor position is between
certain characters. For example, I would like to know if my cursor is between
[ and ].

Jezebel said:
Hard to suggest a work-around without knowing what you're actually trying to
do; but in general the answer is: don't use the Selection object. It's never
necessary, and there are always better ways.


MikeT said:
Hello,

I have a macro that causes Word to hang when the macro is run in a
document
that contains comments (the comment "bubbles"). In my macro, I use the
Selection.MoveUntil method and pass in a negative number or the wdBackward
constant. If the current selection is in front of a comment, MoveUntil
hangs
word if I try to "back up" over the comment.

Here is a simple macro that shows the problem:

Public Sub GoToPrevStar()
Selection.MoveUntil "*", wdBackward
End Sub

Here is an example of a simple document that can be used to reproduce the
problem:
"The * [insert comment here]quick brown fox"

If I place my cursor after the comment (for example, between quick and
brown) and run the GoToPrevStar macro, Word hangs. If I take out the
comment,
the macro works fine.

I have tested this in Word 2003 and Word 2002 and it hangs in both
versions.

Has anyone heard of this problem or a workaround?

Thanks,
Mike
 
J

Jezebel

You might need to specify this a little more fully: is your condition met if
there is a '[' between the start of document and the cursor, and a ']'
between the cursor and the end of document (ie, regardless of what other
characters might lie in between)?


MikeT said:
What I'm trying to do is check to see if the cursor position is between
certain characters. For example, I would like to know if my cursor is
between
[ and ].

Jezebel said:
Hard to suggest a work-around without knowing what you're actually trying
to
do; but in general the answer is: don't use the Selection object. It's
never
necessary, and there are always better ways.


MikeT said:
Hello,

I have a macro that causes Word to hang when the macro is run in a
document
that contains comments (the comment "bubbles"). In my macro, I use the
Selection.MoveUntil method and pass in a negative number or the
wdBackward
constant. If the current selection is in front of a comment, MoveUntil
hangs
word if I try to "back up" over the comment.

Here is a simple macro that shows the problem:

Public Sub GoToPrevStar()
Selection.MoveUntil "*", wdBackward
End Sub

Here is an example of a simple document that can be used to reproduce
the
problem:
"The * [insert comment here]quick brown fox"

If I place my cursor after the comment (for example, between quick and
brown) and run the GoToPrevStar macro, Word hangs. If I take out the
comment,
the macro works fine.

I have tested this in Word 2003 and Word 2002 and it hangs in both
versions.

Has anyone heard of this problem or a workaround?

Thanks,
Mike
 
T

Tony Jollans

The problem is caused by visible balloons.

The best way to avoid it is to avoid working with the selection. The second
best way, if you don't want to do that, is to make sure there are no visible
balloons either by switching to Normal view (Activedocument.view.Type =
wdNormalview) or switching off balloons
(Activedocument.view.revisionsmode=wdinlinerevisions). In both cases it
would be good manners to restore the user's setting when you're done.
 
M

MikeT

Thanks Tony.

Tony Jollans said:
The problem is caused by visible balloons.

The best way to avoid it is to avoid working with the selection. The second
best way, if you don't want to do that, is to make sure there are no visible
balloons either by switching to Normal view (Activedocument.view.Type =
wdNormalview) or switching off balloons
(Activedocument.view.revisionsmode=wdinlinerevisions). In both cases it
would be good manners to restore the user's setting when you're done.

--
Enjoy,
Tony

MikeT said:
Hello,

I have a macro that causes Word to hang when the macro is run in a document
that contains comments (the comment "bubbles"). In my macro, I use the
Selection.MoveUntil method and pass in a negative number or the wdBackward
constant. If the current selection is in front of a comment, MoveUntil hangs
word if I try to "back up" over the comment.

Here is a simple macro that shows the problem:

Public Sub GoToPrevStar()
Selection.MoveUntil "*", wdBackward
End Sub

Here is an example of a simple document that can be used to reproduce the
problem:
"The * [insert comment here]quick brown fox"

If I place my cursor after the comment (for example, between quick and
brown) and run the GoToPrevStar macro, Word hangs. If I take out the comment,
the macro works fine.

I have tested this in Word 2003 and Word 2002 and it hangs in both versions.

Has anyone heard of this problem or a workaround?

Thanks,
Mike
 

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