{"id":65813,"date":"2007-01-03T17:23:00","date_gmt":"2007-01-03T17:23:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/01\/03\/how-can-i-clear-all-the-formatting-from-a-microsoft-word-document\/"},"modified":"2007-01-03T17:23:00","modified_gmt":"2007-01-03T17:23:00","slug":"how-can-i-clear-all-the-formatting-from-a-microsoft-word-document","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-clear-all-the-formatting-from-a-microsoft-word-document\/","title":{"rendered":"How Can I Clear All the Formatting From 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 clear all the formatting from a Microsoft Word document?<BR><BR>&#8212; TF<\/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, TF. After a much-deserved holiday hiatus we are back, with the first official <I>Hey, Scripting Guy!<\/I> column for the year 2007. And yes, we know: technically we <I>did<\/I> have a column <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/jan07\/hey0102.mspx\"><B>yesterday<\/B><\/A>. As it turns out, however, that column was actually written a few weeks ago, before the Scripting Guy who writes this column left on vacation. Because of that, we don\u2019t really consider it to be the first official column for the year 2007. If you looked at yesterday\u2019s column we ask that you forget everything you read there.<\/P>\n<P>And no, for most of you that <I>won\u2019t<\/I> be much of a problem, will it?<\/P>\n<P>Seeing as how this <I>is<\/I> the first official column for the year 2007, do we have plans to make today\u2019s article extra-special and worthwhile? You bet we do; unfortunately, though, none of the other Scripting Guys wrote an extra-special , worthwhile article while the Scripting Guy who writes this column was away. Therefore, instead of anything extra-special you\u2019re getting a simple little script that we scraped together at the last possible minute. Which, if nothing else, means that you don\u2019t have anything to worry about: <I>Hey, Scripting Guy!<\/I> is still the same as it ever was!<\/P>\n<TABLE class=\"dataTable\" id=\"EVD\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P><B>Note<\/B>. Speaking of which, did anyone watch the Fiesta Bowl game between Boise State and Oklahoma? Holy smokes! The stupid \u201cBowl Championship Series\u201d aside, you simply <I>have<\/I> to love college football.<\/P>\n<P>And yes, you <I>do<\/I> have to love it. That\u2019s just the way it goes.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Now, where were we? Ah, yes: a script that removes all the formatting from 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.Open(&#8220;C:\\Scripts\\Test.doc&#8221;)<\/p>\n<p>objDoc.Select<\/p>\n<p>Set objSelection = objWord.Selection\nobjSelection.ClearFormatting\n<\/PRE>\n<P>You can see why we chose this topic on our first day back to work: there really isn\u2019t much to this thing at all. We start off by creating an instance of the ever-popular <B>Word.Application<\/B> object, then set the <B>Visible<\/B> property to True; that gives us a running instance of Microsoft Word that we can see on screen. As soon as Word is up and running we then use the <B>Open<\/B> method 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>As you might expect, Test.doc is a document absolutely <I>rife<\/I> with fancy formatting:<\/P><IMG height=\"295\" alt=\"Microsoft Word\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/noformat1.jpg\" width=\"375\" border=\"0\"> \n<P><BR>Remember, we <I>did <\/I>say fancy formatting, not beautiful formatting.<\/P>\n<P>As it turns out, Microsoft Word includes a built-in command that enables you to remove all the formatting applied to the selected text. What does that mean for us? For one thing, that means that, in order to remove the formatting from the entire document we first need to select the entire document. That\u2019s something we can do by calling the <B>Document<\/B> object\u2019s <B>Select<\/B> method, which \u2013 when called without any additional parameters \u2013 selects the entire document:<\/P><PRE class=\"codeSample\">objDoc.Select\n<\/PRE>\n<P>After we\u2019ve selected all the text we just need to do two more things: create an instance of Word\u2019s <B>Selection<\/B> object, then call that object\u2019s <B>ClearFormatting<\/B> method. That requires just two additional lines of code:<\/P><PRE class=\"codeSample\">Set objSelection = objWord.Selection\nobjSelection.ClearFormatting\n<\/PRE>\n<P>So what\u2019s the net result? <I>This<\/I> is the net result:<\/P><IMG height=\"290\" alt=\"Microsoft Word\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/noformat2.jpg\" width=\"375\" border=\"0\"> \n<P><BR>Not bad for the first day back, if we do say so ourselves.<\/P>\n<P>Speaking of the first day back, that\u2019s a good question: is the Scripting Guy who writes this column excited about coming back to work after three weeks of lounging around watching football and basketball? Let\u2019s put it this way: he\u2019s every bit as thrilled about and dedicated to his job as he was before he went on vacation.<\/P>\n<P>We\u2019ll let you figure out what that means. Like they say, we report; you decide.<\/P><BR>\n<DIV>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"\"><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/jan07\/hey0103.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/technet\/mnplibrary\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/jan07\/hey0103.mspx#top\">Top of page<\/A><\/TD><\/TR><\/TBODY><\/TABLE><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I clear all the formatting from a Microsoft Word document?&#8212; TF Hey, TF. After a much-deserved holiday hiatus we are back, with the first official Hey, Scripting Guy! column for the year 2007. And yes, we know: technically we did have a column yesterday. As it turns out, however, that [&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-65813","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 clear all the formatting from a Microsoft Word document?&#8212; TF Hey, TF. After a much-deserved holiday hiatus we are back, with the first official Hey, Scripting Guy! column for the year 2007. And yes, we know: technically we did have a column yesterday. As it turns out, however, that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65813","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=65813"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65813\/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=65813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=65813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=65813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}