{"id":66343,"date":"2006-10-03T14:21:00","date_gmt":"2006-10-03T14:21:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/10\/03\/how-can-i-add-a-blank-line-between-the-existing-paragraphs-in-a-word-document\/"},"modified":"2006-10-03T14:21:00","modified_gmt":"2006-10-03T14:21:00","slug":"how-can-i-add-a-blank-line-between-the-existing-paragraphs-in-a-word-document","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-add-a-blank-line-between-the-existing-paragraphs-in-a-word-document\/","title":{"rendered":"How Can I Add a Blank Line Between the Existing Paragraphs in a Word Document?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I add a line between the existing paragraphs in a Word document?<BR><BR>&#8212; GB<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, GB. You\u2019ll have to forgive us if we seem a little distracted this morning; shocking as this might seem, the Scripting Guy who writes this column may have made a monumental mistake. In <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/oct06\/hey1002.mspx\"><B>yesterday\u2019s column<\/B><\/A> he joked about an email he received that told him that he had won the \u201cSpainsh\u201d lottery. That sounded like a classic Internet scam, and he treated it as such.<\/P>\n<P>But maybe he shouldn\u2019t have done that. After all, the same day that column was written the same Scripting Guy who made fun of the Spanish lottery received a letter in the mail inviting him to join \u201cupscale people such as yourself\u201d in a private jet club, a club where membership entitles you to a certain number of hours per year flitting about the world in a private jet. \u201cFrequent flyers such as you can surely appreciate the benefits of a private jet over commercial air travel,\u201d noted the letter. As if they even had to ask a question like that!<\/P>\n<TABLE id=\"EDD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. In case you\u2019re wondering, the most airplane trips the Scripting Guy who writes this column has ever taken in a single year is three: one to Pasadena to watch the Huskies beat Purdue in the Rose Bowl; one to Hawaii for a family vacation; and one to Orlando to speak at a conference. This year he hasn\u2019t flown in a plane at all. But still, he probably <I>does<\/I> qualify as a frequent flyer, at least compared to, say, Charlemagne or King Henry the VIII <I>(or the Scripting Editor)<\/I>.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>At first the Scripting Guy who writes this column figured this was just junk mail; high-class junk mail, perhaps, but junk mail nonetheless. But then he got to thinking: how did this private jet company get his name and address? Why did they keep referring to his \u201clavish lifestyle\u201d and appreciation for the finer things in life? How did they <I>know<\/I> that his time is far more valuable than mere money? <\/P>\n<P>As you might expect, he then began to worry. After all, what if the Spanish lottery routinely forwards the names of all their winners to private jet clubs and butler placement agencies and the like? What if the Scripting Guy who writes this column really <I>did<\/I> win one million euros in the Spanish lottery only to throw it all away by making fun of the lottery folks? <\/P>\n<P>That should be a fun thing to go home and try to explain to the family.<\/P>\n<P>But hey: easy come, easy go. Besides, at his current salary, and depending on the exchange rate, it should only take him 300 years or so to make a million euros anyway.<\/P>\n<P>Well, assuming, of course, that his next few performance reviews go a bit better than his last one did.<\/P>\n<P>The bottom line is this: having thrown away a million euros, it looks as though the Scripting Guy who writes this column will have to continue writing this column for a little longer. (But probably just for a few months; as he noted yesterday, he wins the Spanish lottery on a fairly regular basis.) That\u2019s bad news for the Scripting Guy who writes this column, but it\u2019s good news for you, GB; after all, you get a script that can add a line between existing paragraphs in a Word document:<\/P><PRE class=\"codeSample\">Set objWord = CreateObject(&#8220;Word.Application&#8221;)\nobjWord.Visible = True<\/p>\n<p>Set objDoc = objWord.Documents.Open(&#8220;C:\\Scripts\\Test.doc&#8221;)<\/p>\n<p>Set colParagraphs = objDoc.Paragraphs\ncolParagraphs.LineUnitAfter = 1\n<\/PRE>\n<P>To begin with, we should note that there are probably a couple different ways we could have approached this problem. For example, we could have done a search-and-replace and simply replaced all paragraph returns with two paragraph returns. (For more information on writing search-and-replace scripts, see this previous <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/mar06\/hey0321.mspx\"><B>Hey, Scripting Guy!<\/B><\/A> column.) In the end we decided to modify the paragraph format settings so that an additional line would be automatically tacked on to the end of each paragraph in the document. That\u2019s an approach we haven\u2019t used before and, as you just saw, it doesn\u2019t require us to write very much code. (Needless to say, we don\u2019t get paid by the word.)<\/P>\n<P>We should also point out, GB, that we\u2019re assuming you have a Word document that looks something like this:<\/P><IMG border=\"0\" alt=\"Microsoft Word\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/lines1.jpg\" width=\"425\" height=\"400\"> \n<P><BR>As you can see, the paragraphs are all jammed together. We want to space things out a bit by adding a blank line between each of these paragraphs.<\/P>\n<P>To do that we start out by creating an instance of the <B>Word.Application<\/B> object and then setting the <B>Visible<\/B> property to True; that gives us a running instance of Microsoft Word that we can see onscreen. We then use this line of code to open the document C:\\Scripts\\Test.doc:<\/P><PRE class=\"codeSample\">Set objDoc = objWord.Documents.Open(&#8220;C:\\Scripts\\Test.doc&#8221;)\n<\/PRE>\n<P>Believe it or not, that\u2019s the hard part. As soon as the document is open we can use this line of code to retrieve a collection of all the paragraphs in Test.doc:<\/P><PRE class=\"codeSample\">Set colParagraphs = objDoc.Paragraphs\n<\/PRE>\n<P>From there we simply set the value of the <B>LineUnitAfter<\/B> property to 1, which causes 1 blank line to appear after each paragraph in the document:<\/P><PRE class=\"codeSample\">colParagraphs.LineUnitAfter = 1\n<\/PRE>\n<P>Just that easy, just that quick. <\/P>\n<P>But, you interject, what if we wanted <I>2<\/I> blank lines to appear between each paragraph in the document? That\u2019s no problem; one way to do that would be to set the LineUnitAfter property to 2:<\/P><PRE class=\"codeSample\">colParagraphs.LineUnitAfter = 2\n<\/PRE>\n<P>Etc., etc. Alternatively, we could also assign a value to the <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/vbawd11\/html\/woproLineUnitBefore_HV05276164.asp\" target=\"_blank\"><B>LineUnitBefore<\/B><\/A> property, which would cause a blank line to automatically appear <I>before<\/I> each paragraph. Whatever floats your boat, right?<\/P>\n<P>Well, at least for those of you who <I>have<\/I> a boat. <\/P>\n<P>In case you\u2019re wondering, here\u2019s what Test.doc looks like after we run our script:<\/P><IMG border=\"0\" alt=\"Microsoft Word\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/lines2.jpg\" width=\"425\" height=\"400\"> \n<P><BR>Meanwhile, we\u2019re still debating whether we should go ahead and join the private jet club anyway, Spanish lottery or no Spanish lottery. The letter we received didn\u2019t mention the actual price of a membership, which is usually a bad sign. On the other hand, though, the offer <I>did<\/I> include a coupon for $250 off the in-flight catering for our first flight. As you can imagine, it\u2019s awfully hard to pass up an offer like that. (To tell you the truth, we\u2019re not convinced we could even eat $250 worth of food during a single flight. But we\u2019re willing to give it a try.)<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I add a line between the existing paragraphs in a Word document?&#8212; GB Hey, GB. You\u2019ll have to forgive us if we seem a little distracted this morning; shocking as this might seem, the Scripting Guy who writes this column may have made a monumental mistake. In yesterday\u2019s column he [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[84,49,3,5],"class_list":["post-66343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-word","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I add a line between the existing paragraphs in a Word document?&#8212; GB Hey, GB. You\u2019ll have to forgive us if we seem a little distracted this morning; shocking as this might seem, the Scripting Guy who writes this column may have made a monumental mistake. In yesterday\u2019s column he [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=66343"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=66343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=66343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=66343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}