how ctrl+<- dollar amount with unknown # of commas?

I

Ian Elliott

Thanks in advance.

I have a word document that I want to get a number out of
using automation from Excel (I am automating some number
calculations for my boss). I will make a macro that opens
the file, searches for the relevant text, uses the 'end'
key to get to the end of the line, and then "gets" the
dollar amount.
I planned the getting part by ctrl+<- to go back one word,
but it goes back by commas (or periods or dollar signs).
So a number $23,657,832.31 needs eight ctrl+<- to position
the cursor to the left of the dollar sign, when starting
from the right. I am not sure what the dollar amounts (how
many commas, or if periods will be there) will be in
future files, so I shouldn't hard code eight ctrl+<- in
the code. Is there a key that gets to the beginning of a
dollar amount (like ctrl-alt something or other?),
ignoring commas and periods and dollar signs?. Is there
some visual basic code that will do that (like
position.NextWord or whatever?) Or will I have to write
some code that goes back character by character until it
finds a dollar sign?

Any help appreciated.
Thanks again.
 
M

Mark Tangard

Ian,

If you know the amount will always have a dollar sign, you
can use (assuming the Selection is immediately east of the
figure):

Selection.MoveStartUntil CSet:="$", Count:=wdBackward

This moves to the $ and selects the intervening characters.
 

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