Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-10-2011, 05:46 AM
rohanmalhotra rohanmalhotra is offline Help required with spacing Windows XP Help required with spacing Office 2003
Novice
Help required with spacing
 
Join Date: Aug 2011
Posts: 3
rohanmalhotra is on a distinguished road
Unhappy Help required with spacing

Hi



I have created a macro that automatically gives 2 spaces after a period. Unfortunately, it also gives 2 spaces in a URL. Not sure how to rectify this. I have attached the code below :

HTML Code:
Sub TwoSpaces()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "([.])"
        .Replacement.Text = "\1  "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Any help will be appreciated.

Thanks in advance.
Reply With Quote
  #2  
Old 08-10-2011, 06:24 PM
gmaxey gmaxey is offline Help required with spacing Windows XP Help required with spacing Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
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

Try:

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
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-10-2011, 11:24 PM
rohanmalhotra rohanmalhotra is offline Help required with spacing Windows XP Help required with spacing Office 2003
Novice
Help required with spacing
 
Join Date: Aug 2011
Posts: 3
rohanmalhotra is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Try:

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
End Sub
Thanks for your help.
however, it is still not working. what it does is that it deletes spaces after all periods in the document.
Reply With Quote
  #4  
Old 08-11-2011, 04:06 AM
rohanmalhotra rohanmalhotra is offline Help required with spacing Windows XP Help required with spacing Office 2003
Novice
Help required with spacing
 
Join Date: Aug 2011
Posts: 3
rohanmalhotra is on a distinguished road
Default

Hi all

This is really urgent. Can anybody help me with this please?

Many Thanks
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Suggestion required domex Word 0 10-06-2010 05:35 AM
Filename Extensions required in VBA bollivar_corona Word 0 08-06-2010 10:15 AM
Filename Extensions required in VBA bollivar_corona Word VBA 0 08-04-2010 10:33 PM
Help required with spacing Basic help with word required !! bobbybansal Word 1 04-20-2010 02:31 PM
Urgent Help Required id12345 Word 4 12-29-2009 08:22 AM

Other Forums: Access Forums

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