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
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"
Gerald Fay - 16 Jul 2005 20:28 GMT
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
> Hi Gerald,
>
[quoted text clipped - 12 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 16 Jul 2005 20:46 GMT
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"
Gerald Fay - 17 Jul 2005 04:27 GMT
Hyphenated First Names
Verboten!! :)
> Hi Gerald,
>
[quoted text clipped - 6 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"