Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2007

Tip: Looking for answers? Try searching our database.

WordBasic Conversion .ExtendSelection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BobTheElder - 06 Dec 2007 16:40 GMT
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
Klaus Linke - 06 Dec 2007 17:22 GMT
>I am converting some old macros and need a VBA equivalent to the
> WordBasic.ExtendSelection "?" [where ? indicates some character].
[quoted text clipped - 3 lines]
> suggests Selection.ExtendMode = True & Selection.Expand Unit:=wdUnits, which
> is not helpful in this situation.

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
BobTheElder - 06 Dec 2007 18:12 GMT
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.

> Using the macro recorder and a bit of manual editing:
>
[quoted text clipped - 7 lines]
> Regards,
> Klaus
Klaus Linke - 06 Dec 2007 18:12 GMT
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
Jay Freedman - 06 Dec 2007 22:30 GMT
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.

Signature

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.

> Just noticed to things:
>
[quoted text clipped - 12 lines]
>
> Klaus
BobTheElder - 07 Dec 2007 20:04 GMT
Jay & Klaus
Thank you for the different suggestions, I'm learning more and more as I
work on this conversion.

Bob

> 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:
[quoted text clipped - 29 lines]
> >
> > Klaus
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.