VBA or VB.net equivalent of Equivalent of WordBasic WordBasic.SelectCurWord

C

c_shah

I have a old wordbasic code that I am converting to VSTO
what is equivalent of Word 97 (WordBasic) code
WordBasic.SelectCurWord in VSTO

Tried several alternatives

wordApp.Selection.Words.Item(1).Select() OR
WordRange.Words.Item(1).Select()

but it picks up an extra space while WordBasic.SelectCurWord does
not

Here is my situation, following line in my word doc I represents a
bookmark. I am at the bookmark position
wordApp.Selection.Words.Item(1).Select() an extra space (including a
space and reaches upto beginning of word excess)

As it respects the Limit of Liability $ I_______________ excess of $
_______________ , it is

also ,tried this WordApp.Selection.Expand(Word.WdUnits.wdWord) but
it still includes an extra space
 
D

Doug Robbins - Word MVP

Declare a Range object, Set it to the word that you want to capture and then
use

[RangeObject].End = [RangeObject].End - 1

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
C

c_shah

It does not work, I have to select a bookmark named bookmark1 (in my
document it takes me to the beginning of the underline) here is my
code

WordRange = WordDoc.GoTo(What:=Word.WdGoToItem.wdGoToBookmark,
Name:="bookmark1")
WordRange.Words.Item(1).Select()

WordRange.End = WordRange.End - 1
 
J

Jay Freedman

c_shah said:
It does not work, I have to select a bookmark named bookmark1 (in my
document it takes me to the beginning of the underline) here is my
code

WordRange = WordDoc.GoTo(What:=Word.WdGoToItem.wdGoToBookmark,
Name:="bookmark1")
WordRange.Words.Item(1).Select()

WordRange.End = WordRange.End - 1

If you already have a bookmark there, you don't need all this fooling
around. Just write

Set WordRange = WordDoc.Bookmarks("bookmark1").Range

and start working with the range. If for some reason you really need to
select it so the user can do something there, you can follow that with

WordRange.Select

but ask yourself whether that's really necessary.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
D

Doug Robbins - Word MVP

Aside from what Jay has said, you would need to modify the range before you
select it for the modification to be applied to the selection.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jay Freedman

Ah, guilty as charged -- I didn't read the first post in the thread. If my
assumption is correct that the lines are underscore characters rather than
underlined space characters, then this should do:

Dim myRange As Range

Set myRange = ActiveDocument.Bookmarks("bookmark1").Range
myRange.MoveEndWhile Cset:="_", Count:=wdForward

' if necessary, now execute myRange.Select

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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