Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-2018, 08:42 AM
Agog Agog is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2016
Novice
Removing Empty Brackets In Batch
 
Join Date: May 2018
Posts: 11
Agog is on a distinguished road
Default Removing Empty Brackets In Batch


I have only done a little batch editing and can't see a way around this. I have a set of brackets () used before some text in multiple word documents. Is there a way to remove these without removing useful brackets within the documents?
Reply With Quote
  #2  
Old 05-02-2018, 05:33 PM
macropod's Avatar
macropod macropod is offline Removing Empty Brackets In Batch Windows 7 64bit Removing Empty Brackets In Batch Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

That depends on what the criteria are for differentiating useful and useless parentheses.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-03-2018, 05:19 AM
Agog Agog is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2016
Novice
Removing Empty Brackets In Batch
 
Join Date: May 2018
Posts: 11
Agog is on a distinguished road
Default

Thanks for the reply! The criteria for useless brackets in my case is that they are empty and the useful ones have non specific text in.
Reply With Quote
  #4  
Old 05-03-2018, 03:53 PM
eduzs eduzs is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2010 32bit
Expert
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

Why not find and replace "()" with "" ?
Reply With Quote
  #5  
Old 05-03-2018, 04:57 PM
macropod's Avatar
macropod macropod is offline Removing Empty Brackets In Batch Windows 7 64bit Removing Empty Brackets In Batch Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following macro. It will process all documents in the selected folder.
Code:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc as Document 
strDocNm = ActiveDocument.Fullname
strFolder = GetFolder
If strFolder = "" Then Exit Sub 
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      With .Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "()"
        .Replacement.Text = ""
        .Forward = True
        .Format = False
        .Wrap = wdFindContinue
        .MatchWildcards = False
        .Execute Replace:=wdReplaceAll
      End With
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 05-08-2018, 08:01 AM
Agog Agog is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2016
Novice
Removing Empty Brackets In Batch
 
Join Date: May 2018
Posts: 11
Agog is on a distinguished road
Default

The find and replace function can't find "()" for some reason eduzs.
macropod I think I'm falling in love with you... Thanks for yet another perfectly working solution. Case Closed.
Reply With Quote
  #7  
Old 05-08-2018, 08:33 PM
macropod's Avatar
macropod macropod is offline Removing Empty Brackets In Batch Windows 7 64bit Removing Empty Brackets In Batch Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If my macro works, so too should simple Find for (), since all the macro does is automate that for multiple files.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 07-05-2018, 07:39 AM
Agog Agog is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2016
Novice
Removing Empty Brackets In Batch
 
Join Date: May 2018
Posts: 11
Agog is on a distinguished road
Default

For some reason this code has recently stopped working. Also it never worked on find and replace, not sure why...
edit - Might be something to do with the formatting of the brackets. I can type new brackets and use find and replace to change them but not the ones that are currently there, but they look exactly the same... this is really weird. Not sure how your code worked before but doesn't now.

It's like it infects the bracket next to it. If I delete one half of the bracket, save, and try to find it doesn't work. If then I do the same to the other half, it still can't find it. Repeat as many times as you like. If I delete both and replace with my own brackets it works.... any ideas whats happening to me?
Reply With Quote
  #9  
Old 07-05-2018, 04:02 PM
macropod's Avatar
macropod macropod is offline Removing Empty Brackets In Batch Windows 7 64bit Removing Empty Brackets In Batch Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I suspect you had some other character (e.g. a space) between the parentheses; otherwise there is logical reason it wouldn't work. It's hardly surprising it doesn't work if you delete half of the Find string from the document...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 07-06-2018, 12:33 AM
Agog Agog is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2016
Novice
Removing Empty Brackets In Batch
 
Join Date: May 2018
Posts: 11
Agog is on a distinguished road
Default

I wasn't deleting part of the find. I was replacing with a bracket that I wrote rather than the one already in the document. If I only replace half it can't find it. If I then save and replace the other half it still can't find it. But replace both and it can, without altering anything else. There isn't anything in between. I realise this sounds dumb and impossible... Maybe I can send you a document with it in or post an attachment here. I would have to delete everything else in the document as I can't post our company stuff online.
Reply With Quote
  #11  
Old 07-06-2018, 04:34 AM
macropod's Avatar
macropod macropod is offline Removing Empty Brackets In Batch Windows 7 64bit Removing Empty Brackets In Batch Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Without actually seeing the problem document, it can be difficult for anyone to diagnose the issue. Can you attach the document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 07-09-2018, 07:28 AM
Agog Agog is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2016
Novice
Removing Empty Brackets In Batch
 
Join Date: May 2018
Posts: 11
Agog is on a distinguished road
Default

I may have found the problem. It used to have a hyperlink in so maybe the formatting for that is lingering? I removed the hyperlink inside first with the find and replace feature. So maybe the better question is how do you delete a hyperlink enclosed in parentheses.
Also I might be completely wrong with that guess.
Attached is a document with the brackets in. If you find there is strange formatting with them my question is how to remove it and them either separately or together from multiple documents.

Thanks for all your help Macropod and sorry for being a pain.
Attached Files
File Type: docx Macro Test.docx (13.0 KB, 9 views)
Reply With Quote
  #13  
Old 07-09-2018, 04:13 PM
macropod's Avatar
macropod macropod is offline Removing Empty Brackets In Batch Windows 7 64bit Removing Empty Brackets In Batch Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There is still a hyperlink (not just hyperlink formatting) between your parentheses. Try using Ctrl-A,F9 to update the fields in the document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 07-10-2018, 02:44 AM
Agog Agog is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2016
Novice
Removing Empty Brackets In Batch
 
Join Date: May 2018
Posts: 11
Agog is on a distinguished road
Default

So is there a way to remove this from multiple documents? Either in the extended form or the one that just looks like brackets as I can get the documents to move between those, but not find to delete with the normal bracket replacement even with using find brackets with anything inside. (but there are other useful bracket sets in the original documents anyway so that wouldn't help)
Edit - even using the hyperlink style in find and replace doesn't delete the hyperlink fully, just minimises it again.
Reply With Quote
  #15  
Old 07-10-2018, 03:40 AM
gmayor's Avatar
gmayor gmayor is offline Removing Empty Brackets In Batch Windows 10 Removing Empty Brackets In Batch Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

How about

Code:
Sub RemoveBracketedHyperlinks()
Dim hLink As Hyperlink
 Dim oRng As Range
   On Error Resume Next

     For Each hLink In ActiveDocument.Hyperlinks
        Set oRng = hLink.Range
        oRng.Start = oRng.Start - 1
        oRng.End = oRng.End + 1
        If oRng.Characters.First = "(" And _
           oRng.Characters.Last = ")" Then
            oRng.Delete
        End If
    Next hLink
lbl_Exit:
    Set hLink = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a2 is not empty, color empty cells in b2:af2 turkanet Excel 2 08-20-2017 11:00 PM
Removing Empty Brackets In Batch find and delet all text within brackets and the brackets themselves wrdy Word 2 08-03-2017 06:55 PM
Apparently empty (blank) cells aren't empty daymaker Excel 3 03-08-2012 03:41 PM
brackets citation uncung Word 1 07-13-2011 01:39 PM
Brackets Issue... DarkJudge1 Outlook 0 07-06-2010 05:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft