{"id":64243,"date":"2007-08-14T01:25:00","date_gmt":"2007-08-14T01:25:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/08\/14\/how-can-i-insert-a-manual-line-break-into-a-microsoft-word-document\/"},"modified":"2007-08-14T01:25:00","modified_gmt":"2007-08-14T01:25:00","slug":"how-can-i-insert-a-manual-line-break-into-a-microsoft-word-document","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-insert-a-manual-line-break-into-a-microsoft-word-document\/","title":{"rendered":"How Can I Insert a Manual Line Break into a Microsoft Word Document?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! How can I insert a manual line break into a Microsoft Word document?<BR><BR>&#8212; YR <\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, YR. Greetings (<I>saluti<\/I>) from Rome, the Eternal City! You know, according to legend, Rome was founded thousands of years ago by the twins Romulus and Remus, along with their distant cousin (and oldest living Scripting Guy) Peter Costantini. Peter, of course, denies this, inisting that he wasn\u2019t even alive when Romulus and Remus founded the city. That might be true. If so, however, then how does he explain the shirt he always wears, the one that says \u201cI co-founded Rome with Romulus and Remus and all I got was this stupid T-shirt\u201d? <\/P>\n<TABLE class=\"dataTable\" id=\"E6C\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Interesting note<\/B>. According to the <A href=\"http:\/\/babelfish.altavista.com\/\" target=\"_blank\"><B>Babelfish online translation service<\/B><\/A>, the word <I>Costantini, <\/I>when translated from Italian to English, means \u201cCostantini.\u201d Strange but true!<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>We\u2019ll try to figure out who <I>really<\/I> founded Rome as soon as we get the chance. Right now, however, it\u2019s time for breakfast. So far, the Scripting Guy who writes this column has found Italian food to be quite good. After just a couple of days he\u2019s already had, among other things:<\/P>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><I>Bigne<\/I>, a pastry filled with chocolate or vanilla cream.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>Napoleons, a pastry filled with both chocolate and vanilla cream.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><I>Sfogliatelle<\/I>, a pastry filled with a mandarin-flavored ricotta filling.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><I>Pasticiotti<\/I>, another pastry filled with chocolate.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>Fruit tarts, \u00e9clairs, <I>zeppole<\/I>, <I>pastiera<\/I>, <I>cassataSiciliana<\/I>,&nbsp;<I>zuppette<\/I>, and <I>profitteroli<\/I>. All pastries, and all good.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<TABLE class=\"dataTable\" id=\"E4E\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. Is there anything to eat in Italy <I>besides<\/I> pastries? Interesting question; we\u2019ll have to get back to you on that one, too.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>In the meantime, and while we wait for our cappuccino, here\u2019s a script that inserts a manual line break into a Microsoft Word document:<\/P><PRE class=\"codeSample\">Set objWord = CreateObject(&#8220;Word.Application&#8221;)\nobjWord.Visible = True<\/p>\n<p>Set objDoc = objWord.Documents.Add()\nSet objSelection = objWord.Selection<\/p>\n<p>objSelection.TypeText &#8220;This paragraph is followed by a paragraph return.&#8221;\nobjSelection.TypeParagraph()<\/p>\n<p>objSelection.TypeText &#8220;This paragraph is followed by a line break.&#8221; &amp; Chr(11)<\/p>\n<p>objSelection.TypeText &#8220;This paragraph is also followed by a line break.&#8221; &amp; Chr(11)<\/p>\n<p>objSelection.TypeText &#8220;This paragraph is followed by a paragraph return.&#8221;\nobjSelection.TypeParagraph()\n<\/PRE>\n<P>Let\u2019s explain how this script works and, along the way, show you a few pictures that should help convince you that it really <I>does<\/I> work. As you can see, we start out the way most Microsoft Word scripts start out: we create an instance of the <B>Word.Application<\/B> object and then set the <B>Visible<\/B> property to True; that gives us a running instance of Microsoft Word that we can see onscreen. Next we call the <B>Add<\/B> method in order to add a new, blank document to our instance of Word, then use the following line of code to create an instance of Word\u2019s <B>Selection<\/B> object, something that positions the cursor at the beginning of the document and enables us to start adding text:<\/P><PRE class=\"codeSample\">Set objSelection = objWord.Selection\n<\/PRE>\n<P>The first bit of text we add should look relatively familiar; all we\u2019re doing is using the <B>TypeText<\/B> method to type a sentence, then using the <B>TypeParagraph()<\/B> method to add a hard paragraph return (equivalent to pressing the ENTER key on the keyboard) at the end of that sentence:<\/P><PRE class=\"codeSample\">objSelection.TypeText &#8220;This paragraph is followed by a paragraph return.&#8221;\nobjSelection.TypeParagraph()\n<\/PRE>\n<P>Now, take a look at the next piece of text we type into our document:<\/P><PRE class=\"codeSample\">objSelection.TypeText &#8220;This paragraph is followed by a line break.&#8221; &amp; Chr(11)\n<\/PRE>\n<P>Once again we\u2019re using the TypeText method to add a sentence to the document. However, we aren\u2019t just adding a sentence; we\u2019re also adding <B>Chr(11)<\/B> to the end of that sentence. What\u2019s Chr(11)? As it turns out, that\u2019s the ASCII code for a line break. Want to add a line break to the end of a sentence in a Microsoft Word document? Then use Chr(11) rather than the TypeParagraph() method.<\/P>\n<P>And then, just for heck of it, we add a couple more paragraphs, one with a line break, one with a paragraph return.<\/P>\n<P>When the script finishes running our Word document will look like this:<\/P><IMG height=\"363\" alt=\"Microsoft Word\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/returns1.jpg\" width=\"456\" border=\"0\"> \n<P><BR>Granted, that looks like any other Word document. But notice what happens when we click the button that shows us the formatting marks:<\/P><IMG height=\"363\" alt=\"Microsoft Word\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/returns2.jpg\" width=\"456\" border=\"0\"> \n<P><BR>As you can see, lines 1 and 4 have a hard paragraph return after them; by contrast, lines 2 and 3 conclude with a soft paragraph return (a line break). If we center-align just line 2 look what happens:<\/P><IMG height=\"363\" alt=\"Microsoft Word\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/returns3.jpg\" width=\"456\" border=\"0\"> \n<P><BR>Why did lines 3 and 4 also get centered? That\u2019s easy: because they are connected using line break characters rather than paragraph returns. Proof positive that the script works!<\/P>\n<TABLE class=\"dataTable\" id=\"EDH\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P><B>Breaking news flash<\/B>. From what we\u2019ve just been told, Romulus and Remus did <I>not<\/I> co-found the city of Rome. According to the official story (or at least one of many official stories), the two brothers <I>started<\/I> to found the city together; however, Remus felt that Romulus was making the city walls too low. To prove his point, he proceeded to jump over the walls. Romulus, in turn, did what any self-respecting brother would do: he killed Remus, finished building the city, and then named it after himself.<\/P>\n<P>Needless to say, ever since then none of his fellow Scripting Guys have been brave enough to tell Peter that he\u2019s been building <I>his<\/I> walls too low. We\u2019ll just have to make do with the walls the way he built them.<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I insert a manual line break into a Microsoft Word document?&#8212; YR Hey, YR. Greetings (saluti) from Rome, the Eternal City! You know, according to legend, Rome was founded thousands of years ago by the twins Romulus and Remus, along with their distant cousin (and oldest living Scripting Guy) Peter [&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-64243","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 insert a manual line break into a Microsoft Word document?&#8212; YR Hey, YR. Greetings (saluti) from Rome, the Eternal City! You know, according to legend, Rome was founded thousands of years ago by the twins Romulus and Remus, along with their distant cousin (and oldest living Scripting Guy) Peter [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/64243","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=64243"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/64243\/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=64243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=64243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=64243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}