#1
|
|||
|
|||
How to search for unclosed brackets
I have a document with thousands of ( ) and [ ] combinations separated by text.
All sets share only one line How do i search for one item in the pair being missing? |
#2
|
||||
|
||||
You could do that with a series of wildcard Find operations, where:
Find = \([!\)]@^13 to find opening parentheses that lack closing ones; Find = ^13[!\(]@\) to find closing parentheses that lack opening ones; Find = \[[!\]]@^13 to find opening square brackets that lack closing ones; and Find = ^13[!\[]@\] to find closing square brackets that lack opening ones. Alternatively, you could use a macro like: Code:
Sub Demo() Dim oPara As Paragraph For Each oPara In ActiveDocument.Paragraphs With oPara.Range If Len(Replace(.Text, "(", vbNullString)) <> Len(Replace(.Text, ")", vbNullString)) Then .Select MsgBox "Selected paragraph has unmatched smart parentheses", vbExclamation Exit Sub ElseIf Len(Replace(.Text, "[", vbNullString)) <> Len(Replace(.Text, "]", vbNullString)) Then .Select MsgBox "Selected paragraph has unmatched smart square brackets", vbExclamation Exit Sub End If End With Next End Sub For Mac macro installation & usage instructions, see: http://word.mvps.org/Mac/InstallMacro.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi Paul:
Thanks for your reply. Looking at the square bracket routine for search. Does the number of characters between the brackets pairs oi my document matter? It's been over 30 years since I actually wrote a Macro and that was for Excel so I hope it does not come to that. Cheers, Billob |
#4
|
||||
|
||||
The wildcard Find code really only works with what should be one set of parentheses/brackets per paragraph, finding at any that has one parenthesis/bracket but not its counterpart.
The macro is more flexible and works on a paragraph-by-paragraph basis, comparing the number of ( with the number of ) and comparing the number of [ with the number of ] in the same paragraph. It reports & exits if it finds one where the numbers aren't the same, leaving the problem paragraph selected.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Hi Paul:
The search routines work great for my needs. I had to make one change to the 3rd one as it would stop on every line weather it was correct or not. I would have thought that my now Microsoft would have included this option in their search program. Many Thanks billob |
#6
|
||||
|
||||
Quote:
Quote:
!¡, ¿?, <>, {} “”, ‘’, & «», and paired single characters such as: ", ', #, §, |, * & ‡ for enclosing various things which, depending on the document, may span multiple paragraphs. Regardless, as the wildcard Find expressions show, Word does have the means of doing what you wanted.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook leaves 2-3 unclosed tasks | Jennifer Murphy | Outlook | 0 | 08-24-2014 07:08 PM |
Gray square brackets | waldux | Word | 8 | 09-25-2013 04:14 PM |
Finding contents of brackets | return2300 | Word VBA | 0 | 09-04-2013 11:04 AM |
brackets citation | uncung | Word | 1 | 07-13-2011 01:39 PM |
Brackets Issue... | DarkJudge1 | Outlook | 0 | 07-06-2010 05:15 PM |