Sub NoParagraphsAllowed()
For Each Xpara In ActiveDocument.Paragraphs
Xpara.Range.Select
Selection.Characters(Selection.Characters.Count).Delete
Next
End Sub
What this macro does:
This macro will go through an entire Word document and remove all carriage return characters. A carriage return is basically the invisible marker found at every point in the document where the author hit the return key or enter key. A carriage return is also called a paragraph mark, end of paragraph, newline, line feed, hard return, or soft return. In reality, there are differences between the different types of return characters I just listed, but the distinctions are not important for this discussion because this macro will delete all of them.
If the idea of "invisible return characters" is a new concept for you, then you may wish to try the following exercise: Open a document in Word, and open the "Options" box. (You can accomplish this by clicking "Tools," then "Options.") Then click the "View" tab when the Options box opens. The View tab contains a section titled "Formatting Marks." Click "All" under Formatting Marks to fill in the box with a check mark. Voila! Now when you view the document, all the paragraph marks that were previously hidden will now be indicated with a ¶ symbol.
Why I wrote this macro:
Originally, I wrote this macro so that I could quickly "compact" or "compress" my HTML documents. On the one hand, compacting the document has the benefit of reducing the total number of characters in the document, thus reducing the size (in bytes) of the file. However, that was not my initial motivation. The situation that motivated me to write this was the struggle and frustration I was encountering trying to get my HTML resume to display correctly on a career search web site. I would upload the HTML code to the career site, but then my resume would mysteriously display with several extra inches of blank space between paragraphs and between table rows. It took me a while to figure out what was going on, but eventually I discovered that the problem could be eliminated by removing absolutely all unnecessary space characters and carriage return characters from my HTML code.
In other words, I needed to take the original code, which looked something like this:
-
Objective:
To obtain a challenging administrative assistant position where I can contribute my expertise in one or more of the following skill areas:-
Spreadsheets -
I am an advanced user of Excel with extensive knowledge of macros/automation.
-
...and compact it to make it look like this:
- Objective:To obtain a challenging administrative assistant position where I can contribute my expertise in one or more of the following skill areas:
- Spreadsheets - I am an advanced user of Excel with extensive knowledge of macros/automation.
Of course, that is exactly what this macro will do automatically, in one fell swoop!
Other uses for this macro:
This macro is also useful for saving paper when printing long multi-page documents. If you are printing a document because you need a hard copy of the data without much regard to the formatting, then you could use this macro to "compact" the document. With any luck, you will end up printing 5 pages instead of 7, or 20 pages instead of 27. It all depends on how many paragraphs are in the document and how much space separates each paragraph from the next.
For example, I occasionally come across web pages that I would like to print. However, I realize that I could save space and save paper if I were to copy the web page into MS Word rather than printing from my browser. This way, I could reformat the text according to my own needs. I could delete headers, navigation bars, and advertisement text, leaving only the key data that I wish to print. I could then save even more space by running the document compaction macro. This can be very helpful for printing web pages that contain excessive white space between paragraphs.
No comments:
Post a Comment