#1
|
|||
|
|||
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? |
#2
|
||||
|
||||
That depends on what the criteria are for differentiating useful and useless parentheses.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
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.
|
#4
|
|||
|
|||
Why not find and replace "()" with "" ?
|
#5
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
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. |
#7
|
||||
|
||||
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] |
#8
|
|||
|
|||
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? |
#9
|
||||
|
||||
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] |
#10
|
|||
|
|||
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.
|
#11
|
||||
|
||||
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] |
#12
|
|||
|
|||
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. |
#13
|
||||
|
||||
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] |
#14
|
|||
|
|||
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. |
#15
|
||||
|
||||
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 |
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 |
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 |