Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2016, 06:11 AM
mackeex mackeex is offline Locate ALL CAPS in a paragraph Windows 10 Locate ALL CAPS in a paragraph Office 2016
Novice
Locate ALL CAPS in a paragraph
 
Join Date: Jan 2016
Posts: 2
mackeex is on a distinguished road
Default Locate ALL CAPS in a paragraph

Hi to all!

I have this macro:

Sub DeleteCap3Word()
With Selection.Find
.ClearFormatting
.Text = " ([A-Z][A-Z][A-Z]) "
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = True


.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
While .Found
Selection.Find.Execute Replace:=wdReplaceAll
Wend
End With
End Sub

My problem is that it looks for all 3-letter words in all caps including those that I need (ex. MRI, PSA, USB, etc.).

Is there a way to have exceptions so that certain acronyms which I need is not deleted and only 3-letter all caps word which needs to be deleted?

Thank you in advance for your help!!!
Reply With Quote
  #2  
Old 01-08-2016, 06:52 AM
gmaxey gmaxey is online now Locate ALL CAPS in a paragraph Windows 7 32bit Locate ALL CAPS in a paragraph Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

I assume that you are aware that your code will not find three letter CAPS that start the document, end a sentence or paragraph
Code:
Sub DeleteCap3Word()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .Text = " [A-Z]{3} "
    .Replacement.Text = " "
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = True
    .MatchWholeWord = True
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    While .Execute
      Select Case Trim(oRng)
       Case "USB", "PSA"
       
       Case Else
         oRng.Text = " "
     End Select
     oRng.Collapse wdCollapseEnd
   Wend
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 01-08-2016, 07:57 AM
mackeex mackeex is offline Locate ALL CAPS in a paragraph Windows 10 Locate ALL CAPS in a paragraph Office 2016
Novice
Locate ALL CAPS in a paragraph
 
Join Date: Jan 2016
Posts: 2
mackeex is on a distinguished road
Default

Thanks very much! Yeah I have that problem too but those things are quite a few and doesn't affect me that much. I just need to keep those that I need. Anyways thanks a lot for your help!
Reply With Quote
  #4  
Old 01-08-2016, 10:12 PM
macropod's Avatar
macropod macropod is offline Locate ALL CAPS in a paragraph Windows 7 64bit Locate ALL CAPS in a paragraph 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

Alternatively, to handle the exceptions noted by Greg:
Code:
Sub DeleteCap3Word()
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Text = "<[A-Z]{3}>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    Select Case .Text
      Case "MRI", "USB", "PSA"
      Case Else: .Words.First.Delete
    End Select
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Powerpoint 2013 unable to locate word bc320 PowerPoint 0 06-22-2015 08:00 AM
Cannot Locate Archived Messages abraxis Outlook 0 06-10-2014 03:32 PM
Microsoft Office Professional 2010 on Windows 8 problem error cannot locate pst files CDM Outlook 0 12-21-2013 06:36 AM
Can't find Office 2010 product key. How to locate it? alecus Office 1 07-24-2012 04:00 PM
Unable to locate Microsoft Office 2003 Language settings. EzyMe Office 0 09-28-2010 01:09 PM

Other Forums: Access Forums

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