{"id":63963,"date":"2007-09-22T02:15:00","date_gmt":"2007-09-22T02:15:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/09\/22\/how-can-i-apply-a-new-template-to-a-powerpoint-presentation\/"},"modified":"2007-09-22T02:15:00","modified_gmt":"2007-09-22T02:15:00","slug":"how-can-i-apply-a-new-template-to-a-powerpoint-presentation","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-apply-a-new-template-to-a-powerpoint-presentation\/","title":{"rendered":"How Can I Apply a New Template to a PowerPoint Presentation?"},"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! My company has just created a new PowerPoint template, and has decided that we need to use this template for all our presentations. How can I apply this new template to all the presentations in my C:\\Presentations folder?<BR><BR>&#8212; OI<\/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, OI. You know, this morning the Scripting Guy who writes this column did what he does pretty much every weekday morning: stood around the kitchen and waited for the Starbucks iCup coffee maker to brew him a \u201cbean-to-cup, on-demand\u201d cup of coffee. <\/P>\n<TABLE class=\"dataTable\" id=\"E2C\" 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>. In case you\u2019re not familiar with the machine, iCup is short for \u201cInteractive Cup Brewer,\u201d apparently to distinguish it from non-interactive coffee makers. (No one likes those.) Interestingly enough, when the Scripting Guy who writes this column was in elementary school, the term <I>iCup<\/I> was the basis for one of those hilarious-at-the-time grade school jokes: \u201cSpell iCup.\u201d (Spell it and see for yourself.)<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>You know, come to think of it, that\u2019s <I>still<\/I> pretty funny, isn\u2019t it?<\/P>\n<P>At any rate, as the Scripting Guy who writes this column waited for the iCup to interactively brew him a cup of coffee, he spent some time perusing the notices tacked up on the bulletin board. The one that caught his attention was an ad for a local dog boarding facility; what he found interesting is that the facility charges by the pound: it\u2019s $20 a day for dogs who weigh between 30 and 49 pounds; $25 a day for dogs who weigh between 50 and 79 pounds; and so on. That\u2019s fine, except that the Scripting Guy who writes this column was struck by a terrifying thought: what if hotels started charging <I>their<\/I> customers by the pound? Considering the fact that he and fellow Scripting Guy Jean Ross are <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/teched07\/eu.mspx\"><B>headed for Barcelona<\/B><\/A> in November, and considering the fact that he\u2019ll need to stay in a hotel on that trip, well \u2026. We don\u2019t need to tell you that he immediately set down that second doughnut.<\/P>\n<P>OK, granted, he picked it right back up again. But at least the notion gave him pause for thought. <\/P>\n<TABLE class=\"dataTable\" id=\"E1D\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P><B>Note<\/B>. In case you\u2019re wondering, back in the old days Microsoft employees who wanted a cup of coffee walked into the kitchen, set their cup under the spigot for the coffee urn, and pulled the handle; two seconds later they had a cup of coffee. Now you walk into the kitchen, set your cup on the iCup, and punch the buttons; <I>60<\/I> seconds later you have a cup of coffee.<\/P>\n<P>Well, unless you\u2019re like the typical Microsoft employee, who removes the cup after 55 seconds. And yes, that <I>does<\/I> cause coffee to splatter all over the counter. Unfortunately, no one seems to have picked up on that.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Inspired by the dog boarding place, the Scripting Guy who writes this column toyed with the idea of charging by the pound for today\u2019s script, a script that can apply a new template to all the PowerPoint presentations in a folder. However, today\u2019s script is practically weightless: as it turns out, this is a task you can accomplish with just a few lines of code. Therefore, today\u2019s script is free. As for tomorrow\u2019s, well, we\u2019ll see.<\/P>\n<TABLE class=\"dataTable\" id=\"EOE\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P><B>Note<\/B>. Never mind. The Scripting Editor just told us, \u201cNo, we <I>won\u2019t<\/I> see. Tomorrow\u2019s column, and <I>all<\/I> our columns, will be free.\u201d<\/P>\n<P>And yes, she\u2019s <I>always<\/I> like that. Probably drinks too much coffee.<\/P>\n<P><I>Editor\u2019s Note: Maybe, but at least she doesn\u2019t have to worry about a per-pound charge at hotels. Even after eating a doughnut. Or two.<\/I><\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Let\u2019s start out by showing you a script that applies a new template to a single PowerPoint presentation. We\u2019ll explain how that scripts works, then show you a modified version that can apply a template to all the presentations in a folder. Here\u2019s the first script: <\/P><PRE class=\"codeSample\">Set objPPT = CreateObject(&#8220;PowerPoint.Application&#8221;)\nobjPPT.Visible = True<\/p>\n<p>Set objPresentation = objPPT.Presentations.Open(&#8220;C:\\Presentations\\Test.ppt&#8221;)<\/p>\n<p>objPresentation.ApplyTemplate _\n    (&#8220;C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\Ocean.pot&#8221;)<\/p>\n<p>objPresentation.Save<\/p>\n<p>objPPT.Quit\n<\/PRE>\n<P>As you can see, we start out by creating an instance of the <B>PowerPoint.Application<\/B> object. We then set the <B>Visible<\/B> property to True, enabling us to see this instance of PowerPoint on screen. Admittedly, you might think that it\u2019s silly to set the Visible property to True; after all, if everything goes according to plan PowerPoint is only going to be onscreen for a split second. (It will pop up, the template will be changed, and then we\u2019ll save the file and close the application.) For some reason, however, PowerPoint wants to be visible when we go to change the template; if it\u2019s not, the script will crash with the following error:<\/P><PRE class=\"codeSample\">C:\\Scripts\\test.vbs(4, 1) Microsoft Office PowerPoint 2003: Presentations.Open : \nInvalid request.  The PowerPoint Frame window does not exist.\n<\/PRE>\n<P>Fortunately, setting the Visible property to True takes care of that problem.<\/P>\n<P>As soon as PowerPoint is up and running we call the <B>Open<\/B> method to open the file C:\\Presentations\\Test.ppt:<\/P><PRE class=\"codeSample\">Set objPresentation = objPPT.Presentations.Open(&#8220;C:\\Presentations\\Test.ppt&#8221;)\n<\/PRE>\n<P>In case you\u2019re <I>dying<\/I> to know, the first slide in this presentation looks like this:<\/P><IMG height=\"304\" alt=\"Spacer\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/template1.jpg\" width=\"400\" border=\"0\"> \n<P><BR>Of course, we don\u2019t <I>want<\/I> the slide to look that; we want to apply a different template to the presentation. That\u2019s what this line of code is for:<\/P><PRE class=\"codeSample\">objPresentation.ApplyTemplate _\n    (&#8220;C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\Ocean.pot&#8221;)\n<\/PRE>\n<P>As you can see, all we have to do is call the <B>ApplyTemplate<\/B> method, passing the complete file path to the template file as the sole method parameter. Now take a look at slide 1, after ApplyTemplate has had a chance to work its magic:<\/P><IMG height=\"305\" alt=\"Spacer\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/template2.jpg\" width=\"400\" border=\"0\"> \n<P>Not bad, eh?<\/P>\n<P>After that we call the <B>Save<\/B> method to save the modified presentation, then call the <B>Quit<\/B> method to dismiss our instance of PowerPoint. At that point, our work is done.<\/P>\n<P>Well, unless our work involves applying this same template to all the presentations in a folder. Without going into any detail, here\u2019s a script that does just that, applying the Ocean.pot template to all the PPT files in the folder C:\\Presentations:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colFileList = objWMIService.ExecQuery _\n    (&#8220;ASSOCIATORS OF {Win32_Directory.Name=&#8217;C:\\Presentations&#8217;} Where &#8221; _\n        &amp; &#8220;ResultClass = CIM_DataFile&#8221;)<\/p>\n<p>Set objPPT = CreateObject(&#8220;PowerPoint.Application&#8221;)\nobjPPT.Visible = true<\/p>\n<p>For Each objFile In colFileList\n    If objFile.Extension = &#8220;ppt&#8221; Then\n        Set objPresentation = objPPT.Presentations.Open(objFile.Name)\n            objPresentation.ApplyTemplate _\n                (&#8220;C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\Ocean.pot&#8221;)\n        objPresentation.Save\n        objPresentation.Close\n    End If\nNext<\/p>\n<p>objPPT.Quit\n<\/PRE>\n<P>And <I>now<\/I> our work is done.<\/P>\n<P>Incidentally, if any of you know of a good dog boarding kennel in Barcelona, well, please drop us a line. Admittedly, it\u2019s more traditional to stay in a hotel when attending a trade show. But take a look at the description for Mazzu&#8217;s Canine &amp; Feline Luxury Hotel in Philadelphia:<\/P>\n<TABLE class=\"dataTable\" id=\"EHH\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\">Personal suite, platform bed, comforter, toys, TV\/DVD, two walks, one 40-minute jaunt to the dog park, feedings, unlimited bottled water, climate-controlled facility, daily maid service, 24-hour on-site care.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>And, for just $25 more, they\u2019ll toss in a filet mignon dinner delivered to your room. That\u2019s <I>way<\/I> better service than what you get at a people hotel.<\/P>\n<P>Or at least at the people hotels that Microsoft is willing to pay for.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! My company has just created a new PowerPoint template, and has decided that we need to use this template for all our presentations. How can I apply this new template to all the presentations in my C:\\Presentations folder?&#8212; OI Hey, OI. You know, this morning the Scripting Guy who writes this column [&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":[129,49,3,5],"class_list":["post-63963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-powerpoint","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! My company has just created a new PowerPoint template, and has decided that we need to use this template for all our presentations. How can I apply this new template to all the presentations in my C:\\Presentations folder?&#8212; OI Hey, OI. You know, this morning the Scripting Guy who writes this column [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63963","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=63963"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63963\/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=63963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=63963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=63963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}