{"id":49863,"date":"2010-05-11T00:01:00","date_gmt":"2010-05-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/05\/11\/hey-scripting-guy-how-can-i-change-the-theme-of-a-microsoft-powerpoint-presentation\/"},"modified":"2010-05-11T00:01:00","modified_gmt":"2010-05-11T00:01:00","slug":"hey-scripting-guy-how-can-i-change-the-theme-of-a-microsoft-powerpoint-presentation","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-change-the-theme-of-a-microsoft-powerpoint-presentation\/","title":{"rendered":"Hey, Scripting Guy! How Can I Change the Theme of a Microsoft PowerPoint Presentation?"},"content":{"rendered":"<p><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" 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\">Hey, Scripting Guy! We have received our summer student interns, and I asked them to create some Microsoft PowerPoint presentations for me. Unfortunately, the theme they used was not something I can use in the business world. I hate to have the students go back through all of the presentations they created and apply a new theme because I sort of feel like it is my fault. I guess I should not have told an 18-year-old summer student to pick out themes that &ldquo;look nice.&rdquo; Is there a script that can be written to change the theme of a Microsoft PowerPoint presentation?<\/p>\n<p class=\"MsoNormal\">&#8212; GS<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" 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\">Hello GS, <\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. I have been going through the posts on the <a href=\"http:\/\/bit.ly\/asSgxb\"><font face=\"Segoe\">Official Scripting Guys Forum<\/font><\/a> and answering a few of the questions that have been lingering for a while. One of the really cool things about the forum is the number of extremely dedicated and smart moderators we have. I enjoy reading their answers because often I learn new techniques that will be useful to me later. The answers received from the forum are generally pretty quick because we have so many moderators. I have also been checking the e-mail sent to <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a>, and that&rsquo;s when I ran across your question and thought it would make a pretty cool script. The complete FindPowerPointAndApplyTheme.ps1 is shown here.<\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>FindPowerPointAndApplyTheme.ps1<\/p>\n<p><\/strong><\/p>\n<p class=\"CodeBlockScreened\"><span><br \/><font><font face=\"Lucida Sans Typewriter\">Add-type -AssemblyName office<br \/>$Application = New-Object -ComObject powerpoint.application<br \/>$application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue<br \/>$parentPath = $Application.Path | Split-Path -Parent<br \/>$themePath = Join-Path -Path $parentPath -childPath &#8220;Document Themes 14&#8221;<br \/>$path = &#8220;c:fso&#8221;<br \/>Get-ChildItem -Path $path -Include &#8220;*.ppt&#8221;, &#8220;*.pptx&#8221; -Recurse |<br \/>ForEach-Object {<br \/><span>&nbsp;<\/span>$presentation = $application.Presentations.open($_.fullname)<br \/><span>&nbsp;<\/span>$presentation.ApplyTemplate($(Join-Path -Path $themePath -ChildPath &#8220;angles.thmx&#8221;))<br \/><span>&nbsp;<\/span>$presentation.Save()<br \/><span>&nbsp;<\/span>$presentation.Close()<br \/><span>&nbsp;<\/span>&#8220;Modifying $_.FullName&#8221;<br \/>}<\/p>\n<p>$application.quit()<br \/>$application = $null<br \/>[gc]::collect()<br \/>[gc]::WaitForPendingFinalizers()<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The first thing you need to do is to use the <b>Add-Type<\/b> cmdlet to add the <b>Office<\/b> core assembly to our Windows PowerShell session. For more information about this, see <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/05\/10\/hey-scripting-guy-may-10-2010.aspx\">yesterday&rsquo;s Hey, Scripting Guy post<\/a>. You also need to create an instance of the <b>powerpoint<\/b> application object, and set it to visible by using the <b>msoTrue<\/b> value from the <b>MsoTriState<\/b> enumeration:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Add-type -AssemblyName office<br \/>$Application = New-Object -ComObject powerpoint.application<br \/>$application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">Now it is time to retrieve the folder containing the Microsoft Office installation. This location is normally c:Program Files, but on my computer, the installation directory is on an E drive: <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; $Application = New-Object -ComObject powerpoint.application<br \/>PS C:&gt; $Application.Path<br \/>E:Program FilesMicrosoft OfficeOffice14<br \/>PS C:&gt;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">With Office 2010, the themes are in a folder called &ldquo;Document Themes 14&rdquo;:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of location of themes in Office 2010\" alt=\"Image of location of themes in Office 2010\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/may\/hey0511\/hsg-05-11-10-01.jpg\" width=\"600\" height=\"420\"><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/may\/hey0511\/hsg-05-11-10-01.jpg\"><font face=\"Segoe\"><\/font><\/a><\/p>\n<p class=\"MsoNormal\">There is no way to directly retrieve the location for the theme files (.thmx file extension); therefore, it is necessary to build up the path. To do this, the Microsoft PowerPoint application path parent folder is split using the <b>Split-Path<\/b> cmdlet and stored in the <b>$parentPath<\/b> variable. On my computer, this parent path is shown here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; $Application.Path | Split-Path -Parent<br \/>E:Program FilesMicrosoft Office<br \/>PS C:&gt;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">Next, the <b>Join-Path<\/b> cmdlet is used to build up the location for the theme templates. The parent path is joined with the &ldquo;Document Themes 14&rdquo; folder. The code that does this is shown here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">$parentPath = $Application.Path | Split-Path -Parent<br \/>$themePath = Join-Path -Path $parentPath -childPath &#8220;Document Themes 14&#8221;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">After getting the prelimina\nries out of the way, the next thing to do is to use the <b>Get-ChildItem<\/b> cmdlet to retrieve all of the Microsoft PowerPoint presentations in a specific folder. I chose the c:fso folder, but you will probably need to modify the value of the <b>$path<\/b> variable to meet your specific needs. The resulting <b>FIleInfo<\/b> objects are piped to the <b>ForEach-Object<\/b> cmdlet:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">$path = &#8220;c:fso&#8221;<br \/>Get-ChildItem -Path $path -Include &#8220;*.ppt&#8221;, &#8220;*.pptx&#8221; -Recurse |<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The <b>ForEach-Object <\/b>cmdlet accepts the <b>FileInfo<\/b> objects that were returned by the <b>Get-ChildItem<\/b> cmdlet, and it uses the <b>$_ <\/b>automatic variable to refer to the current item on the pipeline. The <b>fullname<\/b> property contains the complete path to the Microsoft PowerPoint files that were found by the <b>Get-ChildItem<\/b> cmdlet. The <b>open<\/b> method is used to open the presentation. The presentations that are returned on my computer do not have a theme or a template applied to them. As shown in the following image, the presentations are relatively plain.<\/p>\n<p class=\"Fig-Graphic\"><span><img decoding=\"async\" title=\"Image of plain presentations returned\" alt=\"Image of plain presentations returned\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/may\/hey0511\/hsg-05-11-10-02.jpg\" width=\"600\" height=\"416\"><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/may\/hey0511\/hsg-05-11-10-02.jpg\"><font face=\"Segoe\"><\/font><\/a><\/span><\/p>\n<p class=\"MsoNormal\">The returned presentation object is stored in the <b>$presentation<\/b> variable:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">ForEach-Object {<br \/><span>&nbsp;<\/span>$presentation = $application.Presentations.open($_.fullname)<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">Now it is time to apply the template to the presentation. The <b>ApplyTemplate<\/b> method needs a complete path to the specific theme or template to be applied. In this example, the angles theme is applied:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>$presentation.ApplyTemplate($(Join-Path -Path $themePath -ChildPath &#8220;angles.thmx&#8221;))<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">After applying the theme to the Microsoft PowerPoint presentation, the slides now appear to be more colorful, as shown in the following image.<\/p>\n<p class=\"Fig-Graphic\"><span><img decoding=\"async\" title=\"Image of presentation with theme applied\" alt=\"Image of presentation with theme applied\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/may\/hey0511\/hsg-05-11-10-03.jpg\" width=\"600\" height=\"416\"><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/may\/hey0511\/hsg-05-11-10-03.jpg\"><font face=\"Segoe\"><\/font><\/a><\/span><\/p>\n<p class=\"MsoNormal\">As the script is running, the presentations will open and flash on the screen until the script has finished processing all of the files. Each presentation is saved and closed before the script moves to the next presentation:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>$presentation.Save()<br \/><span>&nbsp;<\/span>$presentation.Close()<br \/><span>&nbsp;<\/span>&#8220;Modifying $_.FullName&#8221;<br \/>}<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">Now it is time to clean up after running the script. These commands were discussed in <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/05\/10\/hey-scripting-guy-may-10-2010.aspx\">yesterday&rsquo;s script<\/a>:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">$application.quit()<br \/>$application = $null<br \/>[gc]::collect()<br \/>[gc]::WaitForPendingFinalizers()<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">GS, that is all there is to using Windows PowerShell to apply themes to a Microsoft PowerPoint presentation. Microsoft PowerPoint Week will continue tomorrow. <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\"><font face=\"Segoe\">Twitter<\/font><\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\"><font face=\"Segoe\">Official Scripting Guys Forum<\/font><\/a>. See you tomorrow. Until then, peace.<\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/span><\/b><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey, Scripting Guy! We have received our summer student interns, and I asked them to create some Microsoft PowerPoint presentations for me. Unfortunately, the theme they used was not something I can use in the business world. I hate to have the students go back through all of the presentations they created and apply [&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,45],"class_list":["post-49863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-powerpoint","tag-office","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Hey, Scripting Guy! We have received our summer student interns, and I asked them to create some Microsoft PowerPoint presentations for me. Unfortunately, the theme they used was not something I can use in the business world. I hate to have the students go back through all of the presentations they created and apply [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/49863","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=49863"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/49863\/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=49863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=49863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=49863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}