S
Sahana
I got this macro in this forum some time back and I find some problem
with it. My previous post is pretty old so it s not sensible to reopen
it. So, I thought I will be good to open a new post.
My need: I want macros NOT to add word "The" before abbreviation IF
placed between ()
Code 1:
This perfectly check for abbreviations at every instance. This again I
found in this forum.
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
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
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
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub
Code 2:
Some modifications are done but is not suiting my needs.
Sub TheBeforeAcronym()
Dim myRange As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange
.Find.Text = "<([A-Z]{2,})>"
.Find.MatchWildcards = True
.Find.Wrap = wdFindStop
.Find.Forward = True
While .Find.Execute
.MoveStart wdCharacter, -4
.MoveEnd wdCharacter, 1
If Not (.Characters(4) = "(" And _
.Characters.Last = ")") And _
Not Left(.Text, 4) = "the " Then
.MoveStart wdCharacter, 4
.Select
rslt = MsgBox(Prompt:= _
"Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel)
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
Application.ScreenRefresh
End If
End If
.MoveEnd wdCharacter, -1
myRange.Collapse wdCollapseEnd
Wend
Selection.Collapse Direction:=wdCollapseEnd
End With
Set myRange = Nothing
End Sub
I hope I get some help here.
Thanks
Sahana
with it. My previous post is pretty old so it s not sensible to reopen
it. So, I thought I will be good to open a new post.
My need: I want macros NOT to add word "The" before abbreviation IF
placed between ()
Code 1:
This perfectly check for abbreviations at every instance. This again I
found in this forum.
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
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
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
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub
Code 2:
Some modifications are done but is not suiting my needs.
Sub TheBeforeAcronym()
Dim myRange As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange
.Find.Text = "<([A-Z]{2,})>"
.Find.MatchWildcards = True
.Find.Wrap = wdFindStop
.Find.Forward = True
While .Find.Execute
.MoveStart wdCharacter, -4
.MoveEnd wdCharacter, 1
If Not (.Characters(4) = "(" And _
.Characters.Last = ")") And _
Not Left(.Text, 4) = "the " Then
.MoveStart wdCharacter, 4
.Select
rslt = MsgBox(Prompt:= _
"Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel)
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
Application.ScreenRefresh
End If
End If
.MoveEnd wdCharacter, -1
myRange.Collapse wdCollapseEnd
Wend
Selection.Collapse Direction:=wdCollapseEnd
End With
Set myRange = Nothing
End Sub
I hope I get some help here.
Thanks
Sahana