Selecting a Hypenated name

G

Gerald Fay

I am using word macros along with Dragon Dictation to create documents. The
documents are patient encounters and each document starts with the
patient's name "George Smith".

Using a word macro at the end of the dictation, I use word to select the
name and then use the selection to name the document i.e. "George
Smith.doc". This works well unless the name is hyphenated i.e. "Mary
White-Jones". This is because the way I selected the text with the macro is
as follows:

Selection.HomeKey Unit:=wdStory
Selection.Extend
Selection.MoveRight Unit:=wdWord, Count:=2

The problem is that Word views a hyphen as a separate word in those
circumstances the Count is 4 not 2. (the hyphen counts as a word).

How can I use VBA to determine if there is a hyphen in the selected text and
if so extend the selection 2 more words?

Thanks
 
H

Helmut Weber

Hi Gerald,

you need another way of defining the patient's name.
Maybe all until the end of the paragraph is the name,
or until the end of the line.

One could check for chr(45), but that wouldn't help
with Mary White-O'Casey, I think.
And there are endlessly more variations.


Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Gerald Fay

I think this works:

Selection.HomeKey Unit:=wdStory
Selection.Extend
If InStr(ActiveDocument.Paragraphs(1).Range.Text, "-") Then
Selection.MoveRight Unit:=wdWord, Count:=4
Else
Selection.MoveRight Unit:=wdWord, Count:=2
End If
 
H

Helmut Weber

Hi Gerald,

how about John-Peter White-Jones?

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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