I'm trying to work my way through this and would appreciate any help I
can receive :)
I will give you examples to hopefully show you what I want. I'm trying
to prevent users from typing ALL caps.
If a user types the following text "THE LAZY BROWN FOX JUMPED SOME SILLY
FENCE" they get different results based on settings in box.
What I would like to see is "The lazy brown fox jumped some silly fence"
with Uppercase - "THE LAZY BROWN FOX JUMPED SOME SILLY FENCE"
with Lowercase - "the lazy brown fox jumped some silly fence"
with First capital - "THE LAZY BROWN FOX JUMPED SOME SILLY FENCE"
with Title Case - "The Lazy Brown Fox Jumped Some Silly Fence"
I found some code using google:
lPosOld = 1
lPos = 1
Set ffld = ActiveDocument.FormFields("Name")
szFieldContent = ffld.Result
Do
lPos = InStr(lPos, szFieldContent, ". ") + 1
If lPos > 1 Then
szNewContent = szNewContent & _
Mid(szFieldContent, lPosOld, lPos) & _
UCase(Mid(szFieldContent, lPos+1, 1)
lPos = lPos + 1
lPosOld = lPos
End if
Loop While lPos > 1
ffld.Result = szNewContent
But it frowns at the section:
szNewContent = szNewContent & _
Mid(szFieldContent, lPosOld, lPos) & _
UCase(Mid(szFieldContent, lPos+1, 1)
I think I understand the jist of the code.. ipos sets current location
in Field, iposold sets previous location, it goes through each character
until it finds a period and then goes one past the space of the period
and changes the case.
I'm not familiar enough with VBA to know if I need to define
sznewcontent beforehand or how to even do that properly :(
If anyone could assist with this I would greatly appreciate it.
Thanks,
Joshua
Doug Robbins - Word MVP - 19 Dec 2006 18:29 GMT
Just use
ActiveDocument.FormFields("Name").Range.Case = wdTitleWord
or
ActiveDocument.FormFields("text1").Range.Case = wdTitleSentence

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> I'm trying to work my way through this and would appreciate any help I can
> receive :)
[quoted text clipped - 49 lines]
>
> Joshua
Joshua - 19 Dec 2006 18:47 GMT
> Just use
>
[quoted text clipped - 3 lines]
>
> ActiveDocument.FormFields("text1").Range.Case = wdTitleSentence
How would I apply this to the exit macro? Which is what I assume I want
to do.
The code you provide is straightforward, I just don't know how to be non
descript and apply it to the current formfield using an exit macro.
Joshua - 19 Dec 2006 19:11 GMT
> Just use
>
[quoted text clipped - 3 lines]
>
> ActiveDocument.FormFields("text1").Range.Case = wdTitleSentence
First off thanks for the help!
How would I apply this to the exit macro? Which is what I assume I want
to do.
The code you provide is straightforward, I just don't know how to be non
descript and apply it to the current formfield using an exit macro.
Jay Freedman - 19 Dec 2006 19:33 GMT
>> Just use
>>
[quoted text clipped - 12 lines]
> non descript and apply it to the current formfield using an exit
> macro.
See http://word.mvps.org/FAQs/TblsFldsFms/GetCurFmFldName.htm for the
general technique.
If your macro is never assigned as the exit macro for any kind of field
other than a text form field, it simplifies to this:
Dim FieldName As String
FieldName = Selection.Bookmarks(Selection.Bookmarks.Count).Name
ActiveDocument.FormFields(FieldName).Range.Case = wdTitleSentence

Signature
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.
Joshua - 19 Dec 2006 20:00 GMT
Thanks alot for your help Jay.
I was able to figure out why I was having such a rough time.
Apparently the bookmarks code for text box's wont work unless you
specify a name for the Text Box.
May seem stupid but thats why my code I was writing wasn't working and
also why your didn't work originally.
Your code worked perfectly once I gave the textbox a name :)
Thanks again!
Joshua
>>> Just use
>>>
[quoted text clipped - 22 lines]
> FieldName = Selection.Bookmarks(Selection.Bookmarks.Count).Name
> ActiveDocument.FormFields(FieldName).Range.Case = wdTitleSentence