PDA

View Full Version : [SOLVED:] Macro to fix different error typos



Fonsi
05-20-2018, 02:50 AM
Hi there,


I´m looking for a macro that makes the following fixes in a document:


1. Any double dot at the end of a sentence should be replaced by a single dot.

For example:

Hello world.. >>> Hello world.

2. Dot + space + dot at the end of a sentence should be replaced by a single dot.


For example:

Hello world. . >>> Hello world.

3. word + double space + word should be replaced by replaced by a single space:


For example:

Hello world >>> Hello world

Not sure if using wildcards will allow to do that in a single macro but will be very appreciated if so!

macropod
05-20-2018, 06:35 PM
You don't need a macro, just a fewFind/Replace operations, where:

Find = ..
Replace = .

Find = . .
Replace = .
Find = ^32^32
Replace = ^32
You could, of course, record these as a macro.

Paul_Hossler
05-21-2018, 09:05 AM
Hi there,

1. Any double dot at the end of a sentence should be replaced by a single dot.

2. Dot + space + dot at the end of a sentence should be replaced by a single dot.

3. word + double space + word should be replaced by replaced by a single space:



Single macro could do all that, but it's the 'end of a sentence' part that is a little tricky

End of a paragraph part is easy, but it is possible to have a Dot+space+Dot somewhere NOT at the end of sentence (maybe unlikely, but possible)

Maybe you could just assume a-z or 0-9 is the last character in the sentence




Sub Macro1()
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([a-z0-9]).{2,}"
.Replacement.Text = "\1."
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

.Execute Replace:=wdReplaceAll

.Text = "([a-z0-9]). {1,}."
.Execute Replace:=wdReplaceAll

.Text = " {2,}"
.Replacement.Text = " "
.Execute Replace:=wdReplaceAll
End With
End Sub