Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

Selecting a Hypenated name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gerald Fay - 16 Jul 2005 19:23 GMT
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
Helmut Weber - 16 Jul 2005 20:16 GMT
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"
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.