I am converting some old macros and need a VBA equivalent to the
WordBasic.ExtendSelection "?" [where ? indicates some character].

My old code uses this mechanism extensively to include various sized text to
subsequently search for in the document. The VB Equivalents help only
suggests Selection.ExtendMode = True & Selection.Expand Unit:=wdUnits, which
is not helpful in this situation.

Bob
Word 2003

Re: WordBasic Conversion .ExtendSelection by Klaus

Klaus
Thu Dec 06 09:22:41 PST 2007


>I am converting some old macros and need a VBA equivalent to the=20
> WordBasic.ExtendSelection "?" [where ? indicates some character].=20
>=20
> My old code uses this mechanism extensively to include various sized =
text to=20
> subsequently search for in the document. The VB Equivalents help only=20
> suggests Selection.ExtendMode =3D True & Selection.Expand =
Unit:=3DwdUnits, which=20
> is not helpful in this situation.

Using the macro recorder and a bit of manual editing:

Selection.ExtendMode =3D True
Selection.Extend Character:=3D"?"
Selection.ExtendMode =3D False

If your macro uses that a lot, and it turns out to be too slow, you =
might post back with what the macro is supposed to do.
There may be faster ways.

Regards,
Klaus

Re: WordBasic Conversion .ExtendSelection by Klaus

Klaus
Thu Dec 06 10:12:31 PST 2007

Just noticed to things:

Setting ExtendMode isn't actually necessary.

And the VBA help for the Extend method has a better code:

With Selection
.StartIsActive =3D False
.Extend Character:=3D"R"
End With

That makes sure you're moving the end of the selection, not the start.
Quite cool that you can move the Start, really. I wasn't aware of that.

Klaus



Re: WordBasic Conversion .ExtendSelection by BobTheElder

BobTheElder
Thu Dec 06 10:12:01 PST 2007

This appears to perform as desired. I've been converting several old macros
and found that it sometimes takes thinking outside the box or a fresh
viewpoint to convert WordBasic. Thank you.

"Klaus Linke" wrote:
> Using the macro recorder and a bit of manual editing:
>
> Selection.ExtendMode = True
> Selection.Extend Character:="?"
> Selection.ExtendMode = False
>
> If your macro uses that a lot, and it turns out to be too slow, you might post back with what the macro is supposed to do.
> There may be faster ways.
>
> Regards,
> Klaus
>

Re: WordBasic Conversion .ExtendSelection by Jay

Jay
Thu Dec 06 14:30:40 PST 2007

And on the principle that there's never just one way to do anything, you
could also use the .MoveEndUntil method, whose Help example goes like this:

With Selection
.MoveEndUntil Cset:="a", Count:=wdForward
.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With

The advantage with this one is that the Cset parameter can be a list of
characters, and the extension will stop when it hits any one of them. If you
wanted to extend to the next punctuation mark, you could write

Cset:=".,;:'!"

or some variation on that. There is also a .MoveStartUntil, and both
.MoveEndWhile and .MoveStartWhile.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Klaus Linke wrote:
> Just noticed to things:
>
> Setting ExtendMode isn't actually necessary.
>
> And the VBA help for the Extend method has a better code:
>
> With Selection
> .StartIsActive = False
> .Extend Character:="R"
> End With
>
> That makes sure you're moving the end of the selection, not the start.
> Quite cool that you can move the Start, really. I wasn't aware of
> that.
>
> Klaus



Re: WordBasic Conversion .ExtendSelection by BobTheElder

BobTheElder
Fri Dec 07 12:04:00 PST 2007

Jay & Klaus
Thank you for the different suggestions, I'm learning more and more as I
work on this conversion.

Bob

"Jay Freedman" wrote:

> And on the principle that there's never just one way to do anything, you
> could also use the .MoveEndUntil method, whose Help example goes like this:
>
> With Selection
> .MoveEndUntil Cset:="a", Count:=wdForward
> .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> End With
>
> The advantage with this one is that the Cset parameter can be a list of
> characters, and the extension will stop when it hits any one of them. If you
> wanted to extend to the next punctuation mark, you could write
>
> Cset:=".,;:'!"
>
> or some variation on that. There is also a .MoveStartUntil, and both
> ..MoveEndWhile and .MoveStartWhile.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
>
> Klaus Linke wrote:
> > Just noticed to things:
> >
> > Setting ExtendMode isn't actually necessary.
> >
> > And the VBA help for the Extend method has a better code:
> >
> > With Selection
> > .StartIsActive = False
> > .Extend Character:="R"
> > End With
> >
> > That makes sure you're moving the end of the selection, not the start.
> > Quite cool that you can move the Start, really. I wasn't aware of
> > that.
> >
> > Klaus
>
>
>