macros to stop considering a set of words

D

Designingsally

i m trying to automate few basic operations that i work on daily basis. and i
encounter this word often "Objective Mapping:". Below is the macro which
searches words with colon. i want macros to stop considering this word. i
addded If myRange.Text <> "Objective Mapping:" Then and looked on the
process through Watch. but no use :-(

any thoughts??
Sub Colon()
Dim orng As Range
Dim myRange As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
If myRange.Text <> "Objective Mapping:" Then
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
sCase = Msgbox("Word after colon should be in lower case.
Change?", vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
Selection.Collapse wdCollapseEnd
End If
Loop
End With
End With
End Sub
thanks in advance.

the code is given below.
 
G

Graham Mayor

The macro will never find 'Object Mapping:'. What the macro in fact does is
to locate
: [A-Z] (a colon followed by a space and then followed by an upper case
letter)
in the line
Do While .Execute(": [A-Z]", MatchWildcards:=True)

So while it would find : O, you are asking it to base a decision on a text
string that comes *before* the colon and which is therefore not part of the
found range.

One approach would be to define another range that includes the two words
that precede the found string and continue the process based on the content
of that string. In the following example I have modified your code to add a
range that encompasses those two words and then looks at that range to see
if your sample text exists. I have left in a messahe box useful while
testing. Remove the apostrophe to see how the macro works

Sub Colon()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Objective Mapping:") = False Then
sCase = MsgBox("Word after colon should be in lower case.
Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Designingsally

Thanks for explaining the functionality for me. I can understand it better.


--
I believe in Hope.

DesigningSally


Graham Mayor said:
The macro will never find 'Object Mapping:'. What the macro in fact does is
to locate
: [A-Z] (a colon followed by a space and then followed by an upper case
letter)
in the line
Do While .Execute(": [A-Z]", MatchWildcards:=True)

So while it would find : O, you are asking it to base a decision on a text
string that comes *before* the colon and which is therefore not part of the
found range.

One approach would be to define another range that includes the two words
that precede the found string and continue the process based on the content
of that string. In the following example I have modified your code to add a
range that encompasses those two words and then looks at that range to see
if your sample text exists. I have left in a messahe box useful while
testing. Remove the apostrophe to see how the macro works

Sub Colon()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Objective Mapping:") = False Then
sCase = MsgBox("Word after colon should be in lower case.
Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
i m trying to automate few basic operations that i work on daily
basis. and i encounter this word often "Objective Mapping:". Below is
the macro which searches words with colon. i want macros to stop
considering this word. i addded If myRange.Text <> "Objective
Mapping:" Then and looked on the process through Watch. but no use :-(

any thoughts??
Sub Colon()
Dim orng As Range
Dim myRange As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
If myRange.Text <> "Objective Mapping:" Then
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
sCase = Msgbox("Word after colon should be in lower case.
Change?", vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
Selection.Collapse wdCollapseEnd
End If
Loop
End With
End With
End Sub
thanks in advance.

the code is given below.
 
G

Greg Maxey

Sally,

While funcitionally the same, Graham's code and be shortened and simplified
considerably by use the range object vice "selection" object in the
procedure:

Sub Colon()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
orng.MoveStart wdWord, -3
If InStr(1, orng.Text, "Objective Mapping:") = False Then
Select Case MsgBox("Word after colon should be in lower case.
Change?", _
vbQuestion + vbYesNoCancel, "Change Case")
Case vbCancel
Exit Sub
Case vbYes
orng.Characters.Last.Case = wdLowerCase
End Select
End If
orng.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


--
Greg Maxey - Word MVP

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



Designingsally said:
Thanks for explaining the functionality for me. I can understand it
better.


--
I believe in Hope.

DesigningSally


Graham Mayor said:
The macro will never find 'Object Mapping:'. What the macro in fact does
is
to locate
: [A-Z] (a colon followed by a space and then followed by an upper case
letter)
in the line
Do While .Execute(": [A-Z]", MatchWildcards:=True)

So while it would find : O, you are asking it to base a decision on a
text
string that comes *before* the colon and which is therefore not part of
the
found range.

One approach would be to define another range that includes the two words
that precede the found string and continue the process based on the
content
of that string. In the following example I have modified your code to add
a
range that encompasses those two words and then looks at that range to
see
if your sample text exists. I have left in a messahe box useful while
testing. Remove the apostrophe to see how the macro works

Sub Colon()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Objective Mapping:") = False Then
sCase = MsgBox("Word after colon should be in lower case.
Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
i m trying to automate few basic operations that i work on daily
basis. and i encounter this word often "Objective Mapping:". Below is
the macro which searches words with colon. i want macros to stop
considering this word. i addded If myRange.Text <> "Objective
Mapping:" Then and looked on the process through Watch. but no use :-(

any thoughts??
Sub Colon()
Dim orng As Range
Dim myRange As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
If myRange.Text <> "Objective Mapping:" Then
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
sCase = Msgbox("Word after colon should be in lower case.
Change?", vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
Selection.Collapse wdCollapseEnd
End If
Loop
End With
End With
End Sub
thanks in advance.

the code is given below.
 
G

Graham Mayor

In this instance I am not convinced that it is simpler for our learning
friend to follow. ;)
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Greg said:
Sally,

While funcitionally the same, Graham's code and be shortened and
simplified considerably by use the range object vice "selection"
object in the procedure:

Sub Colon()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
orng.MoveStart wdWord, -3
If InStr(1, orng.Text, "Objective Mapping:") = False Then
Select Case MsgBox("Word after colon should be in lower case.
Change?", _
vbQuestion + vbYesNoCancel, "Change Case")
Case vbCancel
Exit Sub
Case vbYes
orng.Characters.Last.Case = wdLowerCase
End Select
End If
orng.Collapse wdCollapseEnd
Loop
End With
End With
End Sub



Designingsally said:
Thanks for explaining the functionality for me. I can understand it
better.


--
I believe in Hope.

DesigningSally


Graham Mayor said:
The macro will never find 'Object Mapping:'. What the macro in fact
does is
to locate
[A-Z] (a colon followed by a space and then followed by an upper
case
letter)
in the line
Do While .Execute(": [A-Z]", MatchWildcards:=True)

So while it would find : O, you are asking it to base a decision on
a text
string that comes *before* the colon and which is therefore not
part of the
found range.

One approach would be to define another range that includes the two
words that precede the found string and continue the process based
on the content
of that string. In the following example I have modified your code
to add a
range that encompasses those two words and then looks at that range
to see
if your sample text exists. I have left in a messahe box useful
while testing. Remove the apostrophe to see how the macro works

Sub Colon()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Objective Mapping:") = False
Then sCase = MsgBox("Word after colon should be in
lower case. Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Designingsally wrote:
i m trying to automate few basic operations that i work on daily
basis. and i encounter this word often "Objective Mapping:". Below
is the macro which searches words with colon. i want macros to stop
considering this word. i addded If myRange.Text <> "Objective
Mapping:" Then and looked on the process through Watch. but no use
:-( any thoughts??
Sub Colon()
Dim orng As Range
Dim myRange As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
If myRange.Text <> "Objective Mapping:" Then
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
sCase = Msgbox("Word after colon should be in lower
case. Change?", vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
Selection.Collapse wdCollapseEnd
End If
Loop
End With
End With
End Sub
thanks in advance.

the code is given below.
 
D

Designingsally

Thanks for the reply
I m encountering some problems here. the suggested macros works fine if i
give only one word. But if i m giving more than one word its just not
working. I think the condition is only set only for one word I *think*. I
might be wrong. can u explain what the reason could be? thanks

try this u might understand better.

Bunny: I love carrots
Bugs: This is amazing.

Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
If InStr(1, preRng.Text, "Bunny:")= False Then
If InStr(1, preRng.Text, "Bugs:") = False Then
sCase = Msgbox("Word after colon should be in lower
case.Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If

If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
Selection.Collapse wdCollapseEnd
Loop

End With
End With
End Sub

--
I believe in Hope.

DesigningSally


Graham Mayor said:
In this instance I am not convinced that it is simpler for our learning
friend to follow. ;)
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Greg said:
Sally,

While funcitionally the same, Graham's code and be shortened and
simplified considerably by use the range object vice "selection"
object in the procedure:

Sub Colon()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
orng.MoveStart wdWord, -3
If InStr(1, orng.Text, "Objective Mapping:") = False Then
Select Case MsgBox("Word after colon should be in lower case.
Change?", _
vbQuestion + vbYesNoCancel, "Change Case")
Case vbCancel
Exit Sub
Case vbYes
orng.Characters.Last.Case = wdLowerCase
End Select
End If
orng.Collapse wdCollapseEnd
Loop
End With
End With
End Sub



Designingsally said:
Thanks for explaining the functionality for me. I can understand it
better.


--
I believe in Hope.

DesigningSally


:

The macro will never find 'Object Mapping:'. What the macro in fact
does is
to locate
[A-Z] (a colon followed by a space and then followed by an upper
case
letter)
in the line
Do While .Execute(": [A-Z]", MatchWildcards:=True)

So while it would find : O, you are asking it to base a decision on
a text
string that comes *before* the colon and which is therefore not
part of the
found range.

One approach would be to define another range that includes the two
words that precede the found string and continue the process based
on the content
of that string. In the following example I have modified your code
to add a
range that encompasses those two words and then looks at that range
to see
if your sample text exists. I have left in a messahe box useful
while testing. Remove the apostrophe to see how the macro works

Sub Colon()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Objective Mapping:") = False
Then sCase = MsgBox("Word after colon should be in
lower case. Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Designingsally wrote:
i m trying to automate few basic operations that i work on daily
basis. and i encounter this word often "Objective Mapping:". Below
is the macro which searches words with colon. i want macros to stop
considering this word. i addded If myRange.Text <> "Objective
Mapping:" Then and looked on the process through Watch. but no use
:-( any thoughts??
Sub Colon()
Dim orng As Range
Dim myRange As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
If myRange.Text <> "Objective Mapping:" Then
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
sCase = Msgbox("Word after colon should be in lower
case. Change?", vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
Selection.Collapse wdCollapseEnd
End If
Loop
End With
End With
End Sub
thanks in advance.

the code is given below.
 
D

Designingsally

Hey there
it works perfectly good now. I switched off my sys and restarted it again.
It was fine again. I dont know what happened. Thanks anyways
--
I believe in Hope.

DesigningSally


Designingsally said:
i would to bring to notice that the code work when I m combing 3 or more
macros together. i dont know what the problem and the code seems to execute
perfectly fine.
If i execute colon() alone. it works fine. I dont know where i m going wrong.
try this data

Objective Mapping: Hi
Lesson Name: Helo
Page Layout: Namaste

the macro i was mentioning is
Sub TheBeforeAcronym()
Dim myRange As Range
Dim orng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
.Text = "<([A-Z]{2,})>"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then

Set orng = myRange.Duplicate
orng.Move wdCharacter, -5
orng.MoveEnd wdCharacter, 4
If Not orng.Text = "the " Then
If Not orng.Text = "The " Then
rslt = Msgbox(Prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel)
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
Call Hyphen
Call LNoteColon
Call NoteColon
Call LNotehyphen
Call Notehyphen
Call LTipColon
Call TipColon
Call LTiphyphen
Call Tiphyphen
Call Colon
End Sub



Private Sub Hyphen()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Demonstration Screen- ") = False Then
If InStr(1, preRng.Text, "Practice Screen- ") = False Then
If InStr(1, preRng.Text, "Match the Following- ") = False Then
If InStr(1, preRng.Text, "Match Choice Question-") = False Then
If InStr(1, preRng.Text, "Sequencing- ") = False Then
sCase = Msgbox("Word after colon should be in lower case.Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub



Private Sub LNoteColon()
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 'Word processing
Select Case Msgbox("Note should not be followed by : The Recommended
Word is ", _
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
Private Sub Notehyphen()
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 'Word processing
Select Case Msgbox("Note should not be followed by - The Recommended
Word is ", _
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
Private Sub LNotehyphen()
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 'Word processing
Select Case Msgbox("Note should not be followed by - The Recommended
Word is ", _
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

Private Sub NoteColon()
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 'Word processing
Select Case Msgbox("Note should not be followed by : The Recommended
Word is ", _
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
Private Sub LTipColon()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("Tip: [A-Za-z]{1,}>", MatchWildcards:=True)
orng.Select 'Word processing
Select Case Msgbox("Tip should not be followed by : The Recommended
Word is ", _
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

Private Sub TipColon()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("TIP: [A-Za-z]{1,}>", MatchWildcards:=True)
orng.Select 'Word processing
Select Case Msgbox("Tip should not be followed by : The Recommended
Word is ", _
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
Private Sub LTiphyphen()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("Tip- [A-Za-z]{1,}>", MatchWildcards:=True)
orng.Select 'Word processing
Select Case Msgbox("Tip should not be followed by : The Recommended
Word is ", _
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
 
D

Designingsally

i would to bring to notice that the code work when I m combing 3 or more
macros together. i dont know what the problem and the code seems to execute
perfectly fine.
If i execute colon() alone. it works fine. I dont know where i m going wrong.
try this data

Objective Mapping: Hi
Lesson Name: Helo
Page Layout: Namaste

the macro i was mentioning is
Sub TheBeforeAcronym()
Dim myRange As Range
Dim orng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
..Text = "<([A-Z]{2,})>"
..MatchWildcards = True
..Wrap = wdFindStop
..Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then

Set orng = myRange.Duplicate
orng.Move wdCharacter, -5
orng.MoveEnd wdCharacter, 4
If Not orng.Text = "the " Then
If Not orng.Text = "The " Then
rslt = Msgbox(Prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel)
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
Call Hyphen
Call LNoteColon
Call NoteColon
Call LNotehyphen
Call Notehyphen
Call LTipColon
Call TipColon
Call LTiphyphen
Call Tiphyphen
Call Colon
End Sub



Private Sub Hyphen()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .FInd
..ClearFormatting
..Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Demonstration Screen- ") = False Then
If InStr(1, preRng.Text, "Practice Screen- ") = False Then
If InStr(1, preRng.Text, "Match the Following- ") = False Then
If InStr(1, preRng.Text, "Match Choice Question-") = False Then
If InStr(1, preRng.Text, "Sequencing- ") = False Then
sCase = Msgbox("Word after colon should be in lower case.Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub



Private Sub LNoteColon()
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 'Word processing
Select Case Msgbox("Note should not be followed by : The Recommended
Word is ", _
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
Private Sub Notehyphen()
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 'Word processing
Select Case Msgbox("Note should not be followed by - The Recommended
Word is ", _
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
Private Sub LNotehyphen()
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 'Word processing
Select Case Msgbox("Note should not be followed by - The Recommended
Word is ", _
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

Private Sub NoteColon()
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 'Word processing
Select Case Msgbox("Note should not be followed by : The Recommended
Word is ", _
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
Private Sub LTipColon()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("Tip: [A-Za-z]{1,}>", MatchWildcards:=True)
orng.Select 'Word processing
Select Case Msgbox("Tip should not be followed by : The Recommended
Word is ", _
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

Private Sub TipColon()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("TIP: [A-Za-z]{1,}>", MatchWildcards:=True)
orng.Select 'Word processing
Select Case Msgbox("Tip should not be followed by : The Recommended
Word is ", _
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
Private Sub LTiphyphen()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("Tip- [A-Za-z]{1,}>", MatchWildcards:=True)
orng.Select 'Word processing
Select Case Msgbox("Tip should not be followed by : The Recommended
Word is ", _
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


Private Sub Tiphyphen()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("TIP- [A-Za-z]{1,}>", MatchWildcards:=True)
orng.Select 'Word processing
Select Case Msgbox("Tip should not be followed by - The Recommended
Word is ", _
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









Private Sub Colon()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .FInd
..ClearFormatting
..Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Lesson Name: ") = False Then
If InStr(1, preRng.Text, "Lesson Number: ") = False Then
If InStr(1, preRng.Text, "Bloom's Level: ") = False Then
If InStr(1, preRng.Text, "On-Screen Text: ") = False Then
If InStr(1, preRng.Text, "Graphic Elements: ") = False Then
If InStr(1, preRng.Text, "Page Layout: ") = False Then
If InStr(1, preRng.Text, "Page Description: ") = False Then
If InStr(1, preRng.Text, "Animation Audio: ") = False Then
If InStr(1, preRng.Text, "Animation Description: ") = False Then
If InStr(1, preRng.Text, "Prompt Text:") = False Then
If InStr(1, preRng.Text, "Popup Text Content: ") = False Then
If InStr(1, preRng.Text, "Objective Mapping:") = False Then
If InStr(1, preRng.Text, "Page # ") = False Then
If InStr(1, preRng.Text, "Interactivity: ") = False Then
If InStr(1, preRng.Text, "Tips:") = False Then
If InStr(1, preRng.Text, "Notes to Developer: ") = False Then
If InStr(1, preRng.Text, "Screenshot: ") = False Then
If InStr(1, preRng.Text, "Question Text: ") = False Then
sCase = Msgbox("Word after colon should be in lower case.Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub









--
I believe in Hope.

DesigningSally


Graham Mayor said:
In this instance I am not convinced that it is simpler for our learning
friend to follow. ;)
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Greg said:
Sally,

While funcitionally the same, Graham's code and be shortened and
simplified considerably by use the range object vice "selection"
object in the procedure:

Sub Colon()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
orng.MoveStart wdWord, -3
If InStr(1, orng.Text, "Objective Mapping:") = False Then
Select Case MsgBox("Word after colon should be in lower case.
Change?", _
vbQuestion + vbYesNoCancel, "Change Case")
Case vbCancel
Exit Sub
Case vbYes
orng.Characters.Last.Case = wdLowerCase
End Select
End If
orng.Collapse wdCollapseEnd
Loop
End With
End With
End Sub



Designingsally said:
Thanks for explaining the functionality for me. I can understand it
better.


--
I believe in Hope.

DesigningSally


:

The macro will never find 'Object Mapping:'. What the macro in fact
does is
to locate
[A-Z] (a colon followed by a space and then followed by an upper
case
letter)
in the line
Do While .Execute(": [A-Z]", MatchWildcards:=True)

So while it would find : O, you are asking it to base a decision on
a text
string that comes *before* the colon and which is therefore not
part of the
found range.

One approach would be to define another range that includes the two
words that precede the found string and continue the process based
on the content
of that string. In the following example I have modified your code
to add a
range that encompasses those two words and then looks at that range
to see
if your sample text exists. I have left in a messahe box useful
while testing. Remove the apostrophe to see how the macro works

Sub Colon()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Objective Mapping:") = False
Then sCase = MsgBox("Word after colon should be in
lower case. Change?", _
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Designingsally wrote:
i m trying to automate few basic operations that i work on daily
basis. and i encounter this word often "Objective Mapping:". Below
is the macro which searches words with colon. i want macros to stop
considering this word. i addded If myRange.Text <> "Objective
Mapping:" Then and looked on the process through Watch. but no use
:-( any thoughts??
Sub Colon()
Dim orng As Range
Dim myRange As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(": [A-Z]", MatchWildcards:=True)
If myRange.Text <> "Objective Mapping:" Then
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
sCase = Msgbox("Word after colon should be in lower
case. Change?", vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
Selection.Collapse wdCollapseEnd
End If
Loop
End With
End With
End Sub
thanks in advance.

the code is given below.
 

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