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

Word supports regular expression operations that will do this. RTFM.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.