PDA

View Full Version : Macro for tedious requirement



vpsekhar
02-21-2015, 09:30 AM
Hi,
Unfortunately I got one tedious requirement, need macro on that. Following is my requirement:
Two spaces required after full stop / end of sentence
shall I have any macro on that?

gmaxey
02-21-2015, 02:53 PM
Unfortunately Word doesn't really know what a full stop is:

http://gregmaxey.mvps.org/word_tip_pages/two_spaces_after_period_full_stop.html

vpsekhar
02-21-2015, 05:59 PM
Hi greg,
Thanks a lot for the code. It is working fine. The only problem is after full stop if comma , semi column, manual line break is there this code is not giving any spaces.
Please let me know where shall i include the comma and semi column in this code , so that i will add below things.

1) <, >, " ,',[,],.
2) Paragraph Mark
3) Number between range 0-9

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

rumshar
02-23-2015, 07:37 AM
Hi ,
this may sound funny..but why not use Find & Replace option of excel?
Regards
Rudra

vpsekhar
02-23-2015, 09:44 PM
Hi,
Even i verified that option also, for each of the indiviual option i am getting around 200 results. If i click on 'replace all' options , in some areas it is not replacing. Thats why i am prefering a macro.