Macros to Captalize first letter

D

Designingsally

Hi i got a doc where i want to captalize first letter of every word?
can macros go that?
Selection.Range.Case = wdNextCase ain't helping me
 
D

Designingsally

let me try to elaborate. the macros searchs for NOTE: and then deletes : . I
want the letter after : to be in upper case if in the lower case.

To captalize the macros i know is Selection.Range.Case = wdNextCase. But the
whole word after : is captalization.

THoughts??
the code im trying to use is:

Sub UNOTESmallCase()
Dim oRng As Range
Dim sCase As String
With Selection
..HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [a-z]{1,}>", _
MatchWildcards:=True)
Set oRng = Selection.Range
oRng.Select
sCase = Msgbox("Remove :", vbYesNo, "Change Case")
If sCase = vbYes Then
Selection.HomeKey Unit:=wdLine
Selection.Range.Case = wdNextCase
oRng = Replace(oRng.Text, ":", "")
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
 
G

Greg Maxey

Sally,

Your existing macro wound't find things like "NOTE: Start here" because your
current seach criteria is looking for "NOTE: [a-z]{1,}>" which excludes any
word following the colon that starts with an upper case letter.

Again, it is often easier to perform find and replace operation using the
range object vice the selection object:

Sub UNOTESmallCase()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [A-Za-z]{1,}>", MatchWildcards:=True)
oRng.Select 'So you can see which word is being processed.
Select Case MsgBox("Do you want to remove the colon in this
instance?", _
vbQuestion + vbYesNoCancel, "Remove :")
Case vbCancel
Exit Sub
Case vbYes
oRng = Replace(oRng.Text, ":", "")
If oRng.Words.Last.Characters.First.Case <> wdUpperCase Then
oRng.Words.Last.Characters.First.Case = wdUpperCase
End If
End Select
oRng.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org



Designingsally said:
let me try to elaborate. the macros searchs for NOTE: and then deletes : .
I
want the letter after : to be in upper case if in the lower case.

To captalize the macros i know is Selection.Range.Case = wdNextCase. But
the
whole word after : is captalization.

THoughts??
the code im trying to use is:

Sub UNOTESmallCase()
Dim oRng As Range
Dim sCase As String
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [a-z]{1,}>", _
MatchWildcards:=True)
Set oRng = Selection.Range
oRng.Select
sCase = Msgbox("Remove :", vbYesNo, "Change Case")
If sCase = vbYes Then
Selection.HomeKey Unit:=wdLine
Selection.Range.Case = wdNextCase
oRng = Replace(oRng.Text, ":", "")
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
--
I believe in Hope.

DesigningSally


Designingsally said:
Hi i got a doc where i want to captalize first letter of every word?
can macros go that?
Selection.Range.Case = wdNextCase ain't helping me
 
G

Graham Mayor

If you are only interested in the first letter after the colon, search only
for that letter and not the whole word and then set the found string (here
orng) to upper case eg

Sub UNOTESmallCase()
Dim oRng As Range
Dim sCase As String
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [a-z]", _
MatchWildcards:=True)
Set oRng = Selection.Range
oRng.Select
sCase = MsgBox("Remove :", vbYesNo, _
"Change Case")
If sCase = vbYes Then
oRng.Case = wdUpperCase
oRng = Replace(oRng.Text, ":", "")
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
let me try to elaborate. the macros searchs for NOTE: and then
deletes : . I want the letter after : to be in upper case if in the
lower case.

To captalize the macros i know is Selection.Range.Case = wdNextCase.
But the whole word after : is captalization.

THoughts??
the code im trying to use is:

Sub UNOTESmallCase()
Dim oRng As Range
Dim sCase As String
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [a-z]{1,}>", _
MatchWildcards:=True)
Set oRng = Selection.Range
oRng.Select
sCase = Msgbox("Remove :", vbYesNo, "Change Case")
If sCase = vbYes Then
Selection.HomeKey Unit:=wdLine
Selection.Range.Case = wdNextCase
oRng = Replace(oRng.Text, ":", "")
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
Hi i got a doc where i want to captalize first letter of every word?
can macros go that?
Selection.Range.Case = wdNextCase ain't helping me
 
D

Designingsally

thanks

--
I believe in Hope.

DesigningSally


Graham Mayor said:
If you are only interested in the first letter after the colon, search only
for that letter and not the whole word and then set the found string (here
orng) to upper case eg

Sub UNOTESmallCase()
Dim oRng As Range
Dim sCase As String
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [a-z]", _
MatchWildcards:=True)
Set oRng = Selection.Range
oRng.Select
sCase = MsgBox("Remove :", vbYesNo, _
"Change Case")
If sCase = vbYes Then
oRng.Case = wdUpperCase
oRng = Replace(oRng.Text, ":", "")
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
let me try to elaborate. the macros searchs for NOTE: and then
deletes : . I want the letter after : to be in upper case if in the
lower case.

To captalize the macros i know is Selection.Range.Case = wdNextCase.
But the whole word after : is captalization.

THoughts??
the code im trying to use is:

Sub UNOTESmallCase()
Dim oRng As Range
Dim sCase As String
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [a-z]{1,}>", _
MatchWildcards:=True)
Set oRng = Selection.Range
oRng.Select
sCase = Msgbox("Remove :", vbYesNo, "Change Case")
If sCase = vbYes Then
Selection.HomeKey Unit:=wdLine
Selection.Range.Case = wdNextCase
oRng = Replace(oRng.Text, ":", "")
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
Hi i got a doc where i want to captalize first letter of every word?
can macros go that?
Selection.Range.Case = wdNextCase ain't helping me
 
D

Designingsally

thanks
--
I believe in Hope.

DesigningSally


Greg Maxey said:
Sally,

Your existing macro wound't find things like "NOTE: Start here" because your
current seach criteria is looking for "NOTE: [a-z]{1,}>" which excludes any
word following the colon that starts with an upper case letter.

Again, it is often easier to perform find and replace operation using the
range object vice the selection object:

Sub UNOTESmallCase()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [A-Za-z]{1,}>", MatchWildcards:=True)
oRng.Select 'So you can see which word is being processed.
Select Case MsgBox("Do you want to remove the colon in this
instance?", _
vbQuestion + vbYesNoCancel, "Remove :")
Case vbCancel
Exit Sub
Case vbYes
oRng = Replace(oRng.Text, ":", "")
If oRng.Words.Last.Characters.First.Case <> wdUpperCase Then
oRng.Words.Last.Characters.First.Case = wdUpperCase
End If
End Select
oRng.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org



Designingsally said:
let me try to elaborate. the macros searchs for NOTE: and then deletes : .
I
want the letter after : to be in upper case if in the lower case.

To captalize the macros i know is Selection.Range.Case = wdNextCase. But
the
whole word after : is captalization.

THoughts??
the code im trying to use is:

Sub UNOTESmallCase()
Dim oRng As Range
Dim sCase As String
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("NOTE: [a-z]{1,}>", _
MatchWildcards:=True)
Set oRng = Selection.Range
oRng.Select
sCase = Msgbox("Remove :", vbYesNo, "Change Case")
If sCase = vbYes Then
Selection.HomeKey Unit:=wdLine
Selection.Range.Case = wdNextCase
oRng = Replace(oRng.Text, ":", "")
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
--
I believe in Hope.

DesigningSally


Designingsally said:
Hi i got a doc where i want to captalize first letter of every word?
can macros go that?
Selection.Range.Case = wdNextCase ain't helping me
 

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