Forum Discussion
inarbeth
Jan 31, 2024Copper Contributor
Macro to remove brackets
I wonder if any VBA experts can help. I found online the following macro to remove square brackets. Sub RemoveSquareBrackets() Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find ...
inarbeth
Copper Contributor
Not quite. If there are no brackets, the macro deletes the first character on the page.
Feb 03, 2024
inarbeth Use a similar test
Dim oRng As Range
Set oRng = Selection.Range
With oRng
.Start = ActiveDocument.Range.Start
If InStr(.Text, "(") <> 0 Then
.Start = .Start + InStrRev(.Text, "(") - 1
.Characters(1).Delete
End If
.End = ActiveDocument.Range.End
If InStr(.Text, ")") <> 0 Then
.End = .Start + InStr(.Text, ")")
.Characters(.Characters.Count).Delete
End If
End With
- inarbethFeb 05, 2024Copper ContributorMany thanks Doug.