Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-19-2016, 02:33 PM
billob billob is offline How to search for unclosed brackets Windows 7 64bit How to search for unclosed brackets Office 2003
Novice
How to search for unclosed brackets
 
Join Date: Sep 2016
Posts: 10
billob is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 09-19-2016, 03:20 PM
macropod's Avatar
macropod macropod is offline How to search for unclosed brackets Windows 7 64bit How to search for unclosed brackets Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

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 PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: http://word.mvps.org/Mac/InstallMacro.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-19-2016, 06:25 PM
billob billob is offline How to search for unclosed brackets Windows 7 64bit How to search for unclosed brackets Office 2003
Novice
How to search for unclosed brackets
 
Join Date: Sep 2016
Posts: 10
billob is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 09-19-2016, 06:44 PM
macropod's Avatar
macropod macropod is offline How to search for unclosed brackets Windows 7 64bit How to search for unclosed brackets Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

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]
Reply With Quote
  #5  
Old 09-19-2016, 08:21 PM
billob billob is offline How to search for unclosed brackets Windows 7 64bit How to search for unclosed brackets Office 2003
Novice
How to search for unclosed brackets
 
Join Date: Sep 2016
Posts: 10
billob is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 09-19-2016, 08:41 PM
macropod's Avatar
macropod macropod is offline How to search for unclosed brackets Windows 7 64bit How to search for unclosed brackets Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Quote:
Originally Posted by billob View Post
I had to make one change to the 3rd one as it would stop on every line weather it was correct or not.
Corrected.
Quote:
Originally Posted by billob View Post
I would have thought that my now Microsoft would have included this option in their search program.
I'm not sure why you'd expect there to be a built-in tool for this, since people also use character pairs such as:
!¡, ¿?, <>, {} “”, ‘’, & «»,
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]
Reply With Quote
Reply



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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:03 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