Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 10-12-2013, 06:40 AM
gmaxey gmaxey is offline How to Turn Off Message "Search from the beginning of a document" in a Macro Windows 7 32bit How to Turn Off Message "Search from the beginning of a document" in a Macro Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub FixSpacing()
  Dim oRng As Word.Range
  Set oRng = ActiveDocument.Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    'Spaces after colon to 2 spaces
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "(:)( {1,9})"
    .Replacement.Text = "\1  "
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  TwoSpacesAfterSentence
  Set oRng = ActiveDocument.Range
  With oRng.Find
    'Spaces after ." and .) to 2 spaces
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "(."")( {1,9})"
    .Replacement.Text = "\1  "
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  Set oRng = ActiveDocument.Range
  With oRng.Find
    'Spaces after ." and .) to 2 spaces
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "([.\)])( {1,9})([A-Z])"
    .Replacement.Text = "\1  \3"
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  Set oRng = ActiveDocument.Range
  'Spaces after a comma or numerical digit and between words to 1 space
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "([,0-9A-Za-z])( {2,9})"
    .Replacement.Text = "\1 "
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  Set oRng = ActiveDocument.Range
  'Space before to no space.
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "( {1,9})([,.:;])"
    .Replacement.Text = "\2"
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ".."
    .Replacement.Text = "."
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End Sub
Sub TwoSpacesAfterSentence()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .MatchWildcards = True
    .Text = "(*{2})([.\!\?]) ([A-Z])"
    .Replacement.Text = "\1\2  \3" 'Two spaces between 2 and \
    .Execute Replace:=wdReplaceAll
    .Text = "([.\!\?]) {3,}([A-Z])"
    .Replacement.Text = "\1  \2"
    .Execute Replace:=wdReplaceAll
    'This should prevent most cases of improper double spacing
    'in names (e.g., F. Lee Bailey, George W. Bush, etc.)
    .Text = "([!A-Z][A-Z].)  ([A-Z])" 'Two spaces between ) and (
    .Replacement.Text = "\1 \2"
    .Execute Replace:=wdReplaceAll
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 

Tags
clean up code, suppress messages



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Turn Off Message "Search from the beginning of a document" in a Macro can't turn off "same as previous" traumatiziert Word 8 12-12-2012 03:31 AM
Instant Search's "Display search results as I type when possible" with Exchange lwc Outlook 0 06-01-2011 01:56 AM
How to Turn Off Message "Search from the beginning of a document" in a Macro Instant search not functional because of continuing "indexing" arrigo Outlook 1 12-07-2010 09:13 PM
Outlook search defaulting to "All Mail Items"??? Ninafel Outlook 0 12-02-2010 02:01 PM
Want to search for "class", replacing with document property YetAnotherAuthor Word 0 10-30-2009 09:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:34 PM.


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