{"id":68213,"date":"2006-01-10T13:01:00","date_gmt":"2006-01-10T13:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/01\/10\/how-can-i-change-the-font-name-and-size-for-an-entire-word-document\/"},"modified":"2006-01-10T13:01:00","modified_gmt":"2006-01-10T13:01:00","slug":"how-can-i-change-the-font-name-and-size-for-an-entire-word-document","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-change-the-font-name-and-size-for-an-entire-word-document\/","title":{"rendered":"How Can I Change the Font Name and Size for an Entire 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 change the font name and size for an entire Word document?<BR><BR>&#8212; CD<\/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, CD. You know, this question reminded us of how old we Scripting Guys are getting &#8211; well, all of us except for Jean, of course, who continues to get younger and more beautiful every day.<\/P>\n<TABLE id=\"EYC\" 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>. No, that isn\u2019t <I>really<\/I> true. However, because Jean\u2019s the editor she\u2019ll just edit this column in a way that makes it <I>sound<\/I> like she\u2019s getting younger and more beautiful every day. With that in mind we decided to save her the trouble of having to rewrite the preceding paragraph. Don\u2019t worry about rewriting everything to make yourself sound good, Jean: it\u2019s already taken care of! <I>(Editor\u2019s Note: Thank you. And yes, the preceding paragraph really <\/I>is<I> true. Greg\u2019s just jealous &#8211; he wishes <\/I>he<I> could look younger and more beautiful every day.)<\/I><\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>At any rate, at least <I>some<\/I> of the Scripting Guys are old enough to remember the days when you had no choice but to use the same font and font size (typically Courier 10-point) throughout a document; back in those dark days of computing you didn\u2019t have TrueType, ClearType, OpenType, PostScript or anything even remotely similar. Way back when, Frutiger Linotype and TW Cen MT Condensed Extra Bold were just a dream. Sigh \u2026.<\/P>\n<P>In other words, back then you couldn\u2019t change the font name and size for an entire Word document. In today\u2019s Golden Age of computing, however, all you need to do is run a script like this: <\/P><PRE class=\"codeSample\">Set objWord = CreateObject(&#8220;Word.Application&#8221;)\nobjWord.Visible = True\nSet objDoc = objWord.Documents.Add()\nSet objSelection = objWord.Selection<\/p>\n<p>objSelection.TypeText &#8220;This is the first paragraph.&#8221;\nobjSelection.TypeParagraph()\nobjSelection.TypeText &#8220;This is the second paragraph.&#8221;\nobjSelection.TypeParagraph()\nobjSelection.TypeText &#8220;This is the third paragraph.&#8221;\nobjSelection.TypeParagraph()<\/p>\n<p>Set objRange = objDoc.Range()\nobjRange.Font.Name = &#8220;Arial&#8221;\nobjRange.Font.Size = 10\n<\/PRE>\n<P>Yes, this <I>is<\/I> a very simple little script and, believe it or not, it\u2019s even simpler than it might first appear; after all, about half the code is there just to type some text into our document. We start off by creating an instance of the <B>Word.Application<\/B> object, then setting the <B>Visible<\/B> property to True; that gives us a running instance of Microsoft Word that we can actually see on screen. We use the <B>Add<\/B> method to create a new document, then use this line of code to create a <B>Selection<\/B> object at the very beginning of the document:<\/P><PRE class=\"codeSample\">Set objSelection = objWord.Selection\n<\/PRE>\n<P>We should point out that we don\u2019t <I>have<\/I> to create the Selection object in order to change the font name and size; we do it here simply because we\u2019re creating a new document on-the-fly. If we were opening an existing document we could skip this line of code; in that case, we could also skip this block of code, which just adds some text to the document:<\/P><PRE class=\"codeSample\">objSelection.TypeText &#8220;This is the first paragraph.&#8221;\nobjSelection.TypeParagraph()\nobjSelection.TypeText &#8220;This is the second paragraph.&#8221;\nobjSelection.TypeParagraph()\nobjSelection.TypeText &#8220;This is the third paragraph.&#8221;\nobjSelection.TypeParagraph()\n<\/PRE>\n<P>The fun really begins as soon as we have a Word document that includes some text (either because we created the document ourselves, as we did here, or because we opened an existing document). Probably the easiest way to change the font name and size for all the text in a document is to simply select the entire document and then make those changes to the selection. How hard is <I>that<\/I> going to be? Not hard at all; for example, selecting the entire document is as easy as calling the <B>Range<\/B> method:<\/P><PRE class=\"codeSample\">Set objRange = objDoc.Range()\n<\/PRE>\n<P>Note that we don\u2019t pass any parameters to the Range method; doing so would actually <I>limit<\/I> our selection. (For example, we could tell the Range method to select only characters 1 through 100 in the document.) Calling Range without any parameters puts the entire document (and thus all of our text) into a Range object we called objRange. At that point we can then specify a new font name and font size using code like this:<\/P><PRE class=\"codeSample\">objRange.Font.Name = &#8220;Arial&#8221;\nobjRange.Font.Size = 10\n<\/PRE>\n<P>And there you have it; with any luck all the text in your document will now be 10-point Arial. Not bad for a bunch of old geezers, huh?<\/P>\n<P>Oops; sorry, Jean. Not bad for three old geezers and one young and vibrant editor, huh?<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I change the font name and size for an entire Word document?&#8212; CD Hey, CD. You know, this question reminded us of how old we Scripting Guys are getting &#8211; well, all of us except for Jean, of course, who continues to get younger and more beautiful every day. Note. [&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-68213","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 change the font name and size for an entire Word document?&#8212; CD Hey, CD. You know, this question reminded us of how old we Scripting Guys are getting &#8211; well, all of us except for Jean, of course, who continues to get younger and more beautiful every day. Note. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68213","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=68213"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68213\/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=68213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}