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 / February 2008

Tip: Looking for answers? Try searching our database.

Assigning selected text to autocorrect, changing case

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alan Stancliff - 26 Jan 2008 00:41 GMT
I learned that it is possible to write a macro to assign selected text to an
autocorrect entry from another thread in this forum. So if autocorrect entry
is "uu", then the code would be:
AutoCorrect.Entries.Add Name:="uu", Value:=Selection.Text

But suppose the selected text is in upper case and one wants it to be
assigned to "UU" in title case. How would one do that?
Jay Freedman - 26 Jan 2008 05:16 GMT
>I learned that it is possible to write a macro to assign selected text to an
>autocorrect entry from another thread in this forum. So if autocorrect entry
[quoted text clipped - 3 lines]
>But suppose the selected text is in upper case and one wants it to be
>assigned to "UU" in title case. How would one do that?

Use the StrConv function with the vbProperCase argument to change the string
before storing it:

Sub demo()
   Dim s As String
   If Selection.Type = wdSelectionNormal Then
       s = StrConv(Selection.Text, vbProperCase)
       AutoCorrect.Entries.Add Name:="UU", Value:=s
   End If
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
Alan Stancliff - 26 Jan 2008 06:02 GMT
Thanks Jay,

As you can probably tell, I'm a beginner at this. Your advice and website
are both very informative and interesting.

Regards,

Alan

> I learned that it is possible to write a macro to assign selected text to an
> autocorrect entry from another thread in this forum. So if autocorrect entry
[quoted text clipped - 3 lines]
> But suppose the selected text is in upper case and one wants it to be
> assigned to "UU" in title case. How would one do that?
Alan Stancliff - 02 Feb 2008 09:31 GMT
Hi Jay,

I hope you see this. It appears that the suggested code:

s = StrConv(Selection.Text, vbProperCase)
AutoCorrect.Entries.Add Name:="UU", Value:=s

Does not convert to title case but to upper case.

This macro is supposed to copy a selected name in upper case in a
demographic sheet and change it to title case. Instead, it seems to change it
to sentence case. That's OK if the name on the demographic is JOHNSON and the
autocorrect entry for UU is Johnson. But it falls apart when it is a compound
name like FERNANDEZ-GUTIERREZ. Then the code assigns UU the value of
Fernandez-gutierrez.

I have been looking around for a way to fix this, as I have to deal with a
lot of compound names.

Regards,

Alan

> Thanks Jay,
>
[quoted text clipped - 12 lines]
> > But suppose the selected text is in upper case and one wants it to be
> > assigned to "UU" in title case. How would one do that?
Graham Mayor - 02 Feb 2008 10:11 GMT
I don't think it would ever be possible to fix a hyphenated name so simply,
however

Dim sText As String
sText = Selection.Text
If InStr(1, sText, "-") Then
   sText = Replace(sText, "-", " ")
   sText = StrConv(sText, vbProperCase)
   sText = Replace(sText, " ", "-")
Else
   sText = StrConv(sText, vbProperCase)
End If
AutoCorrect.Entries.Add Name:="UU", Value:=sText

will do so.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi Jay,
>
[quoted text clipped - 35 lines]
>>> But suppose the selected text is in upper case and one wants it to
>>> be assigned to "UU" in title case. How would one do that?
Alan Stancliff - 03 Feb 2008 06:41 GMT
Thanks Graham,

That definitely did it. Now I've got to get me some books on VBA as I'm
beginning to be "curiouser and curiouser."

Regards,

Alan

> I don't think it would ever be possible to fix a hyphenated name so simply,
> however
[quoted text clipped - 51 lines]
> >>> But suppose the selected text is in upper case and one wants it to
> >>> be assigned to "UU" in title case. How would one do that?
Graham Mayor - 03 Feb 2008 07:34 GMT
You'll probably learn more from the Word vba help and by regularly following
the practical solutions in this forum.
http://www.gmayor.com/MSNews.htm  may help make this forum -
microsoft.public.word.vba.general  - more accessible.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thanks Graham,
>
[quoted text clipped - 68 lines]
>>>>> But suppose the selected text is in upper case and one wants it to
>>>>> be assigned to "UU" in title case. How would one do that?
Alan Stancliff - 04 Feb 2008 00:51 GMT
Thanks for the link, Graham. I'll try to set that up on my "Agent"
newsreader. If that fails, I'll fire up OE.

Regards,

Alan

> You'll probably learn more from the Word vba help and by regularly following
> the practical solutions in this forum.
[quoted text clipped - 73 lines]
> >>>>> But suppose the selected text is in upper case and one wants it to
> >>>>> be assigned to "UU" in title case. How would one do that?
 
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.