I am trying to write a Word macro that selects the current word and
then does some processing on that word. What method can I use to
select the current word (ie the one where the cursor is). The words
may contain undercores so I want it to select the whole word. For
example the word may be T_demog.

Thanks,
David

Re: Selecting the current word (including underscore characters) by Tony

Tony
Fri Nov 18 10:24:16 CST 2005

Hi David,

If you want other than Word's definition of a 'word', you must define your
own. You can extend the selection with something like

Selection.MoveEndUntil "., " & vbCr, wdForward
Selection.MoveStartUntil " " & vbCr, wdBackward

This will look forward for a full stop, comma, space, or carriage return and
backward for a space or carriage return. You will need to also look for
other characters depending on your text - semicolon, question mark, etc.-
and what you want to include in your 'word'.

--
Enjoy,
Tony


"davidS" <dstokar@yahoo.com> wrote in message
news:1132326576.776899.88980@o13g2000cwo.googlegroups.com...
> I am trying to write a Word macro that selects the current word and
> then does some processing on that word. What method can I use to
> select the current word (ie the one where the cursor is). The words
> may contain undercores so I want it to select the whole word. For
> example the word may be T_demog.
>
> Thanks,
> David
>



Re: Selecting the current word (including underscore characters) by davidS

davidS
Fri Nov 18 12:02:53 CST 2005

Thanks Tony.

I have a follow up question. Perhaps you can answer it.

I am trying to set a hyperlink on the word selected.
I would like the address of the hyperlink to be: "tables\the word
selected.sas"

For example
suppose the cursor was on the word "t_demog". I'd like to set the
address to
tables\t_demog.sas and the TextToDisplay to be t_demog.

I am trying to set a variable wdName to the text selected and then use
that
to set the address and the TextToDiplay.

See my code below.

Sub set_hyperlink()
'
' set_hyperlink Macro
' Macro recorded 11/18/2005 by David
'
Dim wdName As Characters
Selection.MoveEndUntil "., " & vbCr, wdForward
Set wdName = Selection.Copy
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
Address:="tables\" & "wdName" & ".sas" , SubAddress:="",
ScreenTip:="", _ TextToDisplay:="wdName"
End Sub


Re: Selecting the current word (including underscore characters) by Tony

Tony
Fri Nov 18 13:29:08 CST 2005

Hi David,

If you have the' word' selected then Selection.Text is a string value which
you can use directly or assign to a string variable if you wish.

--
Enjoy,
Tony


"davidS" <dstokar@yahoo.com> wrote in message
news:1132336973.463364.90150@o13g2000cwo.googlegroups.com...
> Thanks Tony.
>
> I have a follow up question. Perhaps you can answer it.
>
> I am trying to set a hyperlink on the word selected.
> I would like the address of the hyperlink to be: "tables\the word
> selected.sas"
>
> For example
> suppose the cursor was on the word "t_demog". I'd like to set the
> address to
> tables\t_demog.sas and the TextToDisplay to be t_demog.
>
> I am trying to set a variable wdName to the text selected and then use
> that
> to set the address and the TextToDiplay.
>
> See my code below.
>
> Sub set_hyperlink()
> '
> ' set_hyperlink Macro
> ' Macro recorded 11/18/2005 by David
> '
> Dim wdName As Characters
> Selection.MoveEndUntil "., " & vbCr, wdForward
> Set wdName = Selection.Copy
> ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
> Address:="tables\" & "wdName" & ".sas" , SubAddress:="",
> ScreenTip:="", _ TextToDisplay:="wdName"
> End Sub
>