{"id":69243,"date":"2005-08-04T15:06:00","date_gmt":"2005-08-04T15:06:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/08\/04\/how-can-i-change-file-locations-for-microsoft-word\/"},"modified":"2005-08-04T15:06:00","modified_gmt":"2005-08-04T15:06:00","slug":"how-can-i-change-file-locations-for-microsoft-word","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-change-file-locations-for-microsoft-word\/","title":{"rendered":"How Can I Change File Locations for Microsoft Word?"},"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! In Microsoft Word, how can I change the file locations for <B>User Templates<\/B> and <B>Workgroup Templates<\/B>?<BR><BR>&#8212; SB<\/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, SB. At least one of the Scripting Guys has always had a lifelong fear that he would write, say, the greatest novel ever written, except that no one would know about it or care about it. Well, not until he died, of course. At that point, the book would be discovered, it would rocket to the top of the best-seller list, and it would be the Scripting <I>Heir<\/I> who would become rich.<\/P>\n<TABLE id=\"ECD\" 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>. To guard against this happening, this Scripting Guy has vowed never to write anything good. So far he\u2019s managed to stick to that promise without any problem.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>This same Scripting Guy has a similar fear regarding scripts for managing Microsoft Office. The Script Center actually has a number of scripts available in the <A href=\"http:\/\/null\/technet\/scriptcenter\/hubs\/office.mspx\"><B>Scripting for Office<\/B><\/A> center that show you how to carry out administrative tasks such as changing file locations. Few people seem to use these, yet <I>tons<\/I> of people ask how they can write scripts for managing Microsoft Office. It\u2019s like that great, undiscovered novel in the attic: if something were to happen to this Scripting Guy, the Scripting Heir would inherit all those scripts. Heaven forbid!<\/P>\n<P>That\u2019s why we decided to do this brief infomercial before answering our question. If you\u2019re looking for scripts that carry out administrative tasks for Microsoft Office be sure to check out the <A href=\"http:\/\/null\/technet\/scriptcenter\/hubs\/office.mspx\"><B>Scripting for Office<\/B><\/A> center. And if you see some 15-year-old kid nosing around there, remind him that his Scripting Dad is in tip-top shape and will probably live for another 100 years. Or more.<\/P>\n<P>As for changing the file locations for User Templates and Workgroup Templates, well, this script ought to do the trick:<\/P><PRE class=\"codeSample\">Const wdUserTemplatesPath = 2\nConst wdWorkgroupTemplatesPath = 3<\/p>\n<p>Set objWord = CreateObject(&#8220;Word.Application&#8221;)\nSet objOptions = objWord.Options<\/p>\n<p>objOptions.DefaultFilePath(wdUserTemplatesPath) = &#8220;C:\\Templates&#8221;\nobjOptions.DefaultFilePath(wdWorkgroupTemplatesPath) = &#8220;C:\\Workgroup\\Templates&#8221;<\/p>\n<p>objWord.Quit\n<\/PRE>\n<P>We begin by defining a pair of constants &#8211; wdUserTemplatesPath and wdWorkgroupTemplatesPath &#8211; that we\u2019ll use to indicate the file locations we want to change. There are a number of other file locations that can be changed using a script; for a complete list (and for the constants and their associated values) see the <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/vbawd11\/html\/wohowConstants_HV01049731.asp\" target=\"_blank\"><B>wdDefaultFilePath enumeration<\/B><\/A> in the Microsoft Word VBA Language Reference on MSDN.<\/P>\n<P>We then create an instance of the <B>Word.Application<\/B> object as well as its child object, <B>Options<\/B>. You might notice in this script that we don\u2019t set the <B>Visible<\/B> property to True like we do in most of our sample scripts. That\u2019s because we don\u2019t want Word to be visible onscreen; we want to open up Word in an invisible window, make our changes, and then close Word without anyone seeing a thing.<\/P>\n<P>To change a file path all we need to do is change the value of the <B>DefaultFilePath<\/B> property, making sure to use one of our constants to indicate <I>which<\/I> file path we want to change. For example, to change the User Templates path to C:\\Templates we use this line of code:<\/P><PRE class=\"codeSample\">objOptions.DefaultFilePath(wdUserTemplatesPath) = &#8220;C:\\Templates&#8221;\n<\/PRE>\n<P>And to change the Workgroup Templates path to C:\\Workgroup\\Templates we use this line of code:<\/P><PRE class=\"codeSample\">objOptions.DefaultFilePath(wdWorkgroupTemplatesPath) = &#8220;C:\\Workgroup\\Templates&#8221;\n<\/PRE>\n<P>That\u2019s all we have to do; we don\u2019t even need to call a Save function of any kind. We change the file locations and then use the <B>Quit<\/B> method to close Word. (If we don\u2019t do that, an invisible instance of Word will continue running in the background.)<\/P>\n<P>And now that people know about the scripts for managing Microsoft Office, we do one other thing: sit back and wait for fame and fortune to roll in.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! In Microsoft Word, how can I change the file locations for User Templates and Workgroup Templates?&#8212; SB Hey, SB. At least one of the Scripting Guys has always had a lifelong fear that he would write, say, the greatest novel ever written, except that no one would know about it or care [&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,395],"class_list":["post-69243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-word","tag-office","tag-scripting-guy","tag-vbscript","tag-word-application"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! In Microsoft Word, how can I change the file locations for User Templates and Workgroup Templates?&#8212; SB Hey, SB. At least one of the Scripting Guys has always had a lifelong fear that he would write, say, the greatest novel ever written, except that no one would know about it or care [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69243","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=69243"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69243\/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=69243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}