My preference for reading books is ebooks over printed books. One thing I like about eBooks is the ability to copy and paste chunks of text into Word documents, that I use to summarize the books for better retention. Often times the text contains arbitrary spaces inbetween words, hyphenation, and or word wraps after being pasted into word, though.:
In this post I would like to share a small Word Macro I use in order to “cleanup” text after it’s being pasted into a Word document from an eBook. Running the macro should turn the example text into this:
The macro is just using the VBA built-in Find method in order to perform multiple successive search and replace actions against a selected text.
- Insert a marker at the end of the selected text “®®”.
- Replace the paragraph mark “^p” with a space.
- Utilize a regular expression in order to replace multiple spaces between words with one.
- Remove hyphenation.
- Replace the end marker with a paragraph mark.
- Remove spaces that precede a period.
- Remove formatting by applying the “Normal” style to the selected text
You can follow the instructions from this youtube video to add the macro to your global word template (normal.dotm) in order to make it available for all your Word document and those over here to add a button to Word’s quick access bar that launches the Macro.
Here is the code: