Created
August 9, 2018 09:33
-
-
Save DBremen/36d2816fff59537486dd1c292a707580 to your computer and use it in GitHub Desktop.
Word Macro to cleanup text copied from eBooks after pasted into MS Word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub RemoveExtraSpaces() | |
Selection.InsertAfter "®®" | |
With Selection.Find | |
.ClearFormatting | |
.Replacement.ClearFormatting | |
.Text = "^p" | |
'What to replace it with | |
.Replacement.Text = " " | |
.Forward = True | |
.Wrap = wdFindStop | |
.Format = False | |
.MatchWildcards = False | |
.Execute Replace:=wdReplaceAll | |
'multi spaces with single space | |
.Text = " [ ]@([! ])" | |
.Replacement.Text = " \1" | |
.Forward = True | |
.Wrap = wdFindStop | |
.Format = False | |
.MatchWildcards = True | |
.Execute Replace:=wdReplaceAll | |
'hyphenation | |
.Text = "- " | |
.Replacement.Text = "" | |
.Forward = True | |
.Wrap = wdFindStop | |
.Format = False | |
.MatchWildcards = True | |
.Execute Replace:=wdReplaceAll | |
.Text = "®®" | |
.Replacement.Text = "^p" | |
.Forward = True | |
.Wrap = wdFindStop | |
.Format = False | |
.MatchWildcards = False | |
.Execute Replace:=wdReplaceAll | |
'space + dot | |
.Text = " ." | |
.Replacement.Text = "." | |
.Forward = True | |
.Wrap = wdFindStop | |
.Format = False | |
.MatchWildcards = True | |
.Execute Replace:=wdReplaceAll | |
Selection.Style = ActiveDocument.Styles("Normal") | |
End With | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment