0

Hello,

I have a special question. I have a word document which contains a lot of brackets. And In the brackets, there are some abbreviation of name, such as (A S P). Now I need to delete the brackets and the spaces in side , change it like this: ASP

I just can' find a way to batch do that automaticlly . Any idea? I'm using word2010

3
Contributors
3
Replies
27
Views
3 Weeks
Discussion Span
Last Post by Kayla_2
0

Hello,

For you case, you can Find and Replace or VBA code. Here are the 2 ways:

M1:
1.Enter (*) in “Find what” text box and Check “Use wildcards” box, to find all square brackets

  1. Clear “Find what” text box and enter [() ] , Click “Find In” and this time choose “Current Selection”.

  2. Press Delete

M2:
Run this VBAcode

Sub DeleteDelimiters(objFind As Find, strLeftDelimiter As String, strRightDelimiter As String, bDeleteSpace As Boolean)
  Dim strFind1 As String
  Dim strFind2 As String

  strFind1 = "\" & strLeftDelimiter & "*\" & strRightDelimiter
  If (bDeleteSpace) Then
    strFind2 = "[" & strLeftDelimiter & "\" & strRightDelimiter & " ]"
  Else
    strFind2 = "[" & strLeftDelimiter & "\" & strRightDelimiter & "]"
  End If

  Selection.HomeKey Unit:=wdStory
  objFind.ClearFormatting
  objFind.Replacement.Text = ""

  While objFind.Execute(FindText:=strFind1, MatchWildcards:=True)
    objFind.Execute FindText:=strFind2, MatchWildcards:=True, _
      ReplaceWith:="", Replace:=wdReplaceAll, Wrap:=wdFindStop
  Wend

End Sub

Sub DeleteBracketsAndSpace()
  Application.ScreenUpdating = False

  '  Delet all parenthesis and the space in it.
  Call DeleteDelimiters(Selection.Find, "(", ")", True)

  Application.ScreenUpdating = True
End Sub
0

Thanks, all, It really helps a lot. I think I have got my solution :)

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.