Brackets

P

Pesach Shelnitz

Hi Sahana,

The macro in the second post in this link does not skip abbreviations in
parentheses, but you can modify it to skip abbreviations in parentheses by
locating the following line

If Len(rlWord) > 1 Then

and additing the following lines after it

rlWord.MoveStart wdCharacter, -1
rlWord.MoveEnd wdCharacter, 1
If rlWord.Characters.First <> "(" And rlWord.Characters.Last <> ")" Then
rlWord.MoveStart wdCharacter, 1
End If
rlWord.MoveEnd wdCharacter, -1
 
S

Sahana

Hi Sahana,

The macro in the second post in this link does not skip abbreviations in
parentheses, but you can modify it to skip abbreviations in parentheses by
locating the following line

If Len(rlWord) > 1 Then

and  additing the following lines after it

rlWord.MoveStart wdCharacter, -1
rlWord.MoveEnd wdCharacter, 1
If rlWord.Characters.First <> "(" And rlWord.Characters.Last <> ")" Then
rlWord.MoveStart wdCharacter, 1
End If
rlWord.MoveEnd wdCharacter, -1

--
Hope this helps,
Pesach Shelnitz







- Show quoted text -

Hello Sheltniz

Can same be done for this code pasted below.

I find this code more useful than the one mentioned before.

I m so sorry I m a novice. I actually don't to fit where to what. Any
help will be appreciated.

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


Thanks

Sahana
 
P

Pesach Shelnitz

Hi Sahana,

I modified the macro to check for parentheses around the acronym, simplified
the way the macro checks for the word "the" before the acronym, and made some
other changes.

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

--
Hope this helps,
Pesach Shelnitz


Sahana said:
Hi Sahana,

The macro in the second post in this link does not skip abbreviations in
parentheses, but you can modify it to skip abbreviations in parentheses by
locating the following line

If Len(rlWord) > 1 Then

and additing the following lines after it

rlWord.MoveStart wdCharacter, -1
rlWord.MoveEnd wdCharacter, 1
If rlWord.Characters.First <> "(" And rlWord.Characters.Last <> ")" Then
rlWord.MoveStart wdCharacter, 1
End If
rlWord.MoveEnd wdCharacter, -1

--
Hope this helps,
Pesach Shelnitz







- Show quoted text -

Hello Sheltniz

Can same be done for this code pasted below.

I find this code more useful than the one mentioned before.

I m so sorry I m a novice. I actually don't to fit where to what. Any
help will be appreciated.

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


Thanks

Sahana
 

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