View Single Post
 
Old 11-12-2017, 12:14 PM
gunner359 gunner359 is offline Windows 10 Office 2016
Novice
 
Join Date: Oct 2017
Posts: 6
gunner359 is on a distinguished road
Question Word hangs when MoveUntil is used and Comment present

Hi All,

Summary: MoveUntil VBA command hangs Word 2016 when a Comment is
within range of a negative or wdBackward Count parameter. MoveEndUntil and
MoveStartUntil also fail. Further testing indicates that setting Count positive
or wdForward works. See details below.

First time poster. Platform is Windows 10 and Office 2016. My customer has a
slew of Word documents that they pass around and edit. They wanted a macro
that allows them to insert text strings into the document that are highlighted
white text on a green background and hidden. Easy enough. I have the user type
a + sign followed by the string. The macro is invoked by the keyboard shortcut
Alt-m; the string from the insertion point (IP) back to the + sign is given a
style I created and the + sign removed. All is working great.

In my macro, I use the VBA commands:

Dim i As Long
...
i = Selection.MoveUntil(Cset:="+", Count:=wdBackward)

to find the + sign and the length of the string (-i-1). Works very well.
When the + sign is missing, the MoveUntil command returns 0 and the
macro is conditioned to handle this case.

But here is the rub. When the user
inserts a Comment in the document and types Alt-m prior to the
Comment, the MoveUntil command returns 0. Good. When the IP is after
the Comment and Alt-m is typed, Word VBA stops on the VBA command

i = Selection.MoveUntil(Cset:="+", Count:=wdBackward)

and the cursor spins looking like a wheel. No error, no nothing.

When I change the Count to -100:

i = Selection.MoveUntil(Cset:="+", Count:=-100)

all works well when Alt-m is typed and the IP is > 100 characters after
the Comment. When the IP is between the Comment and the 100th
character after the Comment, the MoveUntil command hangs
and Word hangs (Not Responding). Word has to be
restarted. Sounds like MoveUntil is confused when it runs into a
Comment. Any ideas? I'm trying not to use Find as the setup a little
tedious and Find would take much longer that MoveUntil (I think).

Any help would be appreciated. Thank you.

Last edited by gunner359; 11-12-2017 at 09:28 PM. Reason: Further testing
Reply With Quote