{"id":65723,"date":"2007-01-16T06:39:00","date_gmt":"2007-01-16T06:39:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/01\/16\/hey-scripting-guy-how-can-i-set-the-default-file-path-in-office-excel-to-a-users-home-directory\/"},"modified":"2007-01-16T06:39:00","modified_gmt":"2007-01-16T06:39:00","slug":"hey-scripting-guy-how-can-i-set-the-default-file-path-in-office-excel-to-a-users-home-directory","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-set-the-default-file-path-in-office-excel-to-a-users-home-directory\/","title":{"rendered":"Hey, Scripting Guy! How Can I Set the Default File Path in Office Excel to a User\u2019s Home Directory?"},"content":{"rendered":"<h2><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" class=\"nearGraphic\" \/> <\/h2>\n<p>Hey, Scripting Guy! How can I set Office Excel&rsquo;s default file path to a user&rsquo;s home directory?<\/p>\n<p>&#8212; LL<\/p>\n<p><img decoding=\"async\" height=\"5\" width=\"5\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" alt=\"Spacer\" border=\"0\" \/><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" class=\"nearGraphic\" \/><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" height=\"288\" width=\"120\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" align=\"right\" alt=\"Script Center\" border=\"0\" title=\"Script Center\" class=\"farGraphic\" \/><\/a><\/p>\n<p>Hey, LL. We hope that the script we&rsquo;re about to show you will answer your question; if it doesn&rsquo;t, you might have to wait awhile before we can get back to you on it. That&rsquo;s because the Scripting Guy who writes this column isn&rsquo;t even at work today; instead, he&rsquo;s spending the day at King County Superior Court in Seattle.<\/p>\n<p>You know, that&rsquo;s what everyone thinks when they first hear the news; as it turns out, though, it&rsquo;s <i>not<\/i> illegal to write a daily scripting column that talks about pretty much everything <i>except<\/i> scripting. (Whether that <i>should<\/i> be illegal is, of course, a different question.) As it is, instead of being on trial himself the Scripting Guy who writes this column received the &ldquo;honor and privilege&rdquo; of being selected for jury duty. Consequently, he&rsquo;ll be spending the day hanging around with hardened criminals, miscreants, and other low-life types.<\/p>\n<p>Which, now that we think about it, pretty much <i>does<\/i> describe a day spent hanging around with the other Scripting Guys, doesn&rsquo;t it?<\/p>\n<p>But don&rsquo;t worry. While the Scripting Guy who writes this column is off battling for truth and justice, he did leave a little something for everyone to remember him by:<\/p>\n<pre class=\"codeSample\">Set objUser = GetObject(\"LDAP:\/\/cn=Ken Myer,ou=Finance,dc=fabrikam,dc=com\")\nstrHomeDirectory = objUser.homeDirectory\n\nSet objExcel = CreateObject(\"Excel.Application\")\nobjExcel.DefaultFilePath = strHomeDirectory\nobjExcel.Quit<\/pre>\n<p>As you can see, what we have here is a two-part script: in part 1 we retrieve the user&rsquo;s home directory, and in part 2 we set Excel&rsquo;s default location to that home directory. To determine the user&rsquo;s home directory we start out by binding to the appropriate user account in Active Directory. We then use this line of code to grab the value of the <b>homeDirectory<\/b> attribute and store it in a variable named strHomeDirectory:<\/p>\n<pre class=\"codeSample\">strHomeDirectory = objUser.homeDirectory<\/pre>\n<p>You know, come to think of it, part 1 <i>was<\/i> pretty easy, wasn&rsquo;t it? That&rsquo;s good. And the good news just keeps on coming: part 2 is equally easy. In the second section of the script we start out by creating an instance of the <b>Excel.Application<\/b> object. As soon as Excel is up and running we then use this line of code to assign the value of the variable strHomeDirectory to the <b>DefaultFilePath<\/b> property:<\/p>\n<pre class=\"codeSample\">objExcel.DefaultFilePath = strHomeDirectory<\/pre>\n<p>That&rsquo;s it; all we have to do now is call the <b>Quit<\/b> method and terminate our instance of Excel.<\/p>\n<p>And you&rsquo;re right: in most of our Excel scripts we use the command <b>objExcel.Visible = True<\/b> in order to make Excel visible onscreen. Why didn&rsquo;t we do that here? Well, for one thing, the script takes only a second or two to run; no sooner would Excel appear on screen then we&rsquo;d be calling the <b>Quit<\/b> method to get rid of it. On top of that, all we&rsquo;re doing is setting an Application object property; as a result, there&rsquo;s really nothing to see onscreen anyway.<\/p>\n<p>You say you have another question: how will the Scripting Guy who writes this column decide whether someone is innocent or guilty? To be honest, he doesn&rsquo;t know; after all, he&rsquo;s never served on a jury before. He does know one thing, however: whoever the accused happens to be had better hope that he or she gave the Scripting Guy who writes this column a good evaluation score during <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/webcasts\/ps.mspx\"><b>Windows PowerShell Week<\/b><\/a>.<\/p>\n<p>Not that we Scripting Guys keep track of that sort of thing, mind you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I set Office Excel&rsquo;s default file path to a user&rsquo;s home directory? &#8212; LL Hey, LL. We hope that the script we&rsquo;re about to show you will answer your question; if it doesn&rsquo;t, you might have to wait awhile before we can get back to you on it. That&rsquo;s because [&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":[711,48,49,3,5],"class_list":["post-65723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-excel-application","tag-microsoft-excel","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I set Office Excel&rsquo;s default file path to a user&rsquo;s home directory? &#8212; LL Hey, LL. We hope that the script we&rsquo;re about to show you will answer your question; if it doesn&rsquo;t, you might have to wait awhile before we can get back to you on it. That&rsquo;s because [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65723","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=65723"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65723\/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=65723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=65723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=65723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}