select the word but not the space behind it

Y

ykchanaed

With Selection
..Moveend Unit:=wdWord, Count:=1
..movestart Unit:=wdWord, Count:=-1
..InsertBefore Text:="("
..InsertAfter Text:=")"
End With

I wrote the above to insert brackets to the word where the cursor locates.
But it included the space behind the word.
any way to improve it?
 
T

Tony Jollans

With Selection
..Expand Unit:=wdWord
..MoveEndWhile Cset:=" ", Count:=wdBackward
..InsertBefore Text:="("
..InsertAfter Text:=")"
End With

It's not perfect - put the cursor to the left or right of punctuation and it
will parenthesise the punctuation - but it would take more complex code to
trap that.
 

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