{"id":25627,"date":"2023-03-01T13:30:50","date_gmt":"2023-03-01T18:30:50","guid":{"rendered":"https:\/\/breakingintowallstreet.com\/?post_type=biws_kb&#038;p=25627"},"modified":"2024-09-11T07:07:20","modified_gmt":"2024-09-11T12:07:20","slug":"macros-in-powerpoint","status":"publish","type":"biws_kb","link":"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/macros-in-powerpoint\/","title":{"rendered":"Macros in PowerPoint: Full Tutorial and How to Write VBA Code for a \u201cSwap Multiple Shapes\u201d Macro"},"content":{"rendered":"<p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-flat ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Macros in PowerPoint: Full Tutorial and How to Write VBA Code for a \u201cSwap Multiple Shapes\u201d Macro<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/macros-in-powerpoint\/#PowerPoint_Macros_and_VBA_in_Excel_vs_PowerPoint\">PowerPoint Macros and VBA in Excel vs. PowerPoint<\/a><\/li><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/macros-in-powerpoint\/#Your_First_PowerPoint_Macro_%E2%80%9CSwap_Shapes%E2%80%9D\">Your First PowerPoint Macro: \u201cSwap Shapes\u201d<\/a><\/li><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/macros-in-powerpoint\/#The_Limitations_of_Macros_in_PowerPoint\">The Limitations of Macros in PowerPoint<\/a><\/li><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/macros-in-powerpoint\/#An_Extension_to_Macros_in_PowerPoint_%E2%80%9CSwap_Multiple_Shapes%E2%80%9D\">An Extension to Macros in PowerPoint: \u201cSwap Multiple Shapes\u201d<\/a><\/li><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/macros-in-powerpoint\/#Macros_in_PowerPoint_Beyond_the_Surface-Level_Detail\">Macros in PowerPoint: Beyond the Surface-Level Detail<\/a><\/li><\/ul><\/nav><\/div>\n<br \/>\n<strong>Macros in PowerPoint<\/strong> are useful for tasks such as performing tricky alignments, fitting shapes within tables, and using Drawing Guides, rather than physical lines, to distribute shapes.<\/p>\n<p>Before you start using macros or writing your own VBA code, you <u>must<\/u> understand the fundamentals of PowerPoint: features like <a href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/powerpoint-quick-access-toolbar\/\" target=\"_blank\" rel=\"noopener\">the Quick Access Toolbar<\/a>, <a href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/powerpoint-slide-master\/\" target=\"_blank\" rel=\"noopener\">the Slide Master<\/a>, <a href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/tables-in-powerpoint\/\" target=\"_blank\" rel=\"noopener\">Tables<\/a>, and <a href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/how-to-duplicate-a-shape-in-powerpoint\/\" target=\"_blank\" rel=\"noopener\">how to duplicate a shape<\/a>.<\/p>\n<p>It\u2019s counterproductive to \u201cautomate\u201d slides and presentations unless you first understand the key PowerPoint commands and shortcuts.<\/p>\n<p>In this tutorial, we\u2019ll walk you through <strong>how to create your first PowerPoint macro<\/strong>, which you can use to swap the positions of multiple shapes.<\/p>\n<p>This code is simple, but it is also very useful because it typically takes several keyboard shortcuts and mouse drags to swap shapes manually, so an automated solution is a clear win.<\/p>\n<p>And amazingly, there is no built-in way to do this in the standard version of PowerPoint.<\/p>\n<div class='code-block code-block-6' style='margin: 8px 0; clear: both;'>\n<div class=\"kb-adinsert-modal\">\n    <div class=\"kb-adinsert-top\">\n      <div class=\"media\">\n          <img decoding=\"async\" class=\"alignnone size-full wp-image-28448\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2024\/05\/22172833\/Power-Point-Pro.png\" alt=\"PowerPoint Pro\" width=\"128\" height=\"128\" \/>\n      <\/div>\n      <div class=\"content\">\n          <h3>Become a PowerPoint Pro With the <strong>BIWS PowerPoint & VBA Course<\/strong><\/h3>\n      <\/div>\n    <\/div>\n    \n    <div class=\"full_text\">\n    \t<ul>\n        \t<li>\n            \t<h4>Become a presentation machine<\/h4>\n              <p>Master the key shortcuts and commands for \u201cwarp speed\u201d slide creation<\/p>\n\t\t\t    <\/li>\n          <li>\n          \t<h4>Acquire the skills with dozens of practice exercises<\/h4>\n            <p>Learn by doing \u2013 and check your work against the solutions<\/p>\n\t\t\t    <\/li>\n          <li>\n          \t<h4>Save hours with our full macro package (25+ macros)<\/h4>\n            <p>Automate formatting, tables, alignment, drawing guides, and more\n\n<\/p>\n\t\t\t  <\/li>\n      <\/ul>\n        \n      <a class=\"cta-link orange-button-medium\" href=\"https:\/\/breakingintowallstreet.com\/powerpoint-pro\/\" target=\"_blank\">Full Details<\/a>\n      \n      <a class=\"cta-link orange-button-medium bg-blue\" href=\"https:\/\/biws-support.s3.us-east-1.amazonaws.com\/Course-Outlines\/PowerPoint-Pro-Course-Outline.pdf\" target=\"_blank\" rel=\"noopener\">Short Outline<\/a>\n    <\/div>\n<\/div>\n<\/div>\n\n<h3><strong>Video Table of Contents:<\/strong><\/h3>\n<p><strong>0:58:<\/strong> Why Macros Are Useful in PowerPoint<\/p>\n<p><strong>2:44:<\/strong> PowerPoint Macro Demo<\/p>\n<p><strong>6:27:<\/strong> Lesson Overview<\/p>\n<p><strong>6:40:<\/strong> VBA in Excel vs. PowerPoint<\/p>\n<p><strong>10:09:<\/strong> Simple &#8220;Shape Swap&#8221; Macro<\/p>\n<p><strong>18:29:<\/strong> Macro to Swap Multiple Shapes<\/p>\n<p><strong>25:29:<\/strong> Recap and Summary<\/p>\n<h3><strong>Files &amp; Resources:<\/strong><\/h3>\n<p><a href=\"https:\/\/youtube-breakingintowallstreet-com.s3.amazonaws.com\/Macros-in-PowerPoint-VBA-Tutorial-Slides.pdf\" target=\"_blank\" rel=\"noopener\">Slide Presentation \u2013 Macros in PowerPoint and VBA Tutorial (PDF)<\/a><\/p>\n<p><a href=\"https:\/\/youtube-breakingintowallstreet-com.s3.amazonaws.com\/Macros-in-PowerPoint-Ref-Slide.pptx\" target=\"_blank\" rel=\"noopener\">Reference Slides for Macro Exercise (PPT)<\/a><\/p>\n<p><a href=\"https:\/\/youtube-breakingintowallstreet-com.s3.amazonaws.com\/Macros-in-PowerPoint-Ref-Slide.pptm\" target=\"_blank\" rel=\"noopener\">\u201cFinished\u201d Version of Macro and Reference Slides (PPTM)<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"PowerPoint_Macros_and_VBA_in_Excel_vs_PowerPoint\"><\/span><strong>PowerPoint Macros and VBA in Excel vs. PowerPoint<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before jumping into the code, it\u2019s worth asking two key questions:<\/p>\n<ol>\n<li>What are the <strong>advantages and disadvantages<\/strong> of VBA and macros in Excel vs. PowerPoint?<\/li>\n<li>What are <strong>good vs. bad use cases<\/strong> for macros in PowerPoint? In other words, what is the <em>most effective <\/em>way to spend your time automating your presentations?<\/li>\n<\/ol>\n<p>On the first question, <a href=\"https:\/\/breakingintowallstreet.com\/kb\/excel\/excel-vba-programming\/\" target=\"_blank\" rel=\"noopener\">VBA in Excel<\/a> is <strong>simpler to set up and use for quick macros<\/strong>.<\/p>\n<p>Excel has a macro recorder, so you can record your actions in a spreadsheet, review them in the VBA Editor, and modify the code to do what you want.<\/p>\n<p>Also, assigning keyboard shortcuts to your macros is easy because you always select a keyboard shortcut when you record actions in the macro recorder.<\/p>\n<p>By contrast, PowerPoint macros are <strong>more difficult to set up but are arguably more powerful<\/strong>.<\/p>\n<p>Most Excel macros function based on a <strong>selected range of cells<\/strong> in a single spreadsheet and automate processes like color-coding the cells or changing the decimal places.<\/p>\n<p>That\u2019s nice, but PowerPoint macros often <strong>change the entire presentation<\/strong>, including on normal slides and templates in <a href=\"https:\/\/breakingintowallstreet.com\/kb\/powerpoint\/powerpoint-slide-master\/\" target=\"_blank\" rel=\"noopener\">the Slide Master<\/a>.<\/p>\n<p>Also, PowerPoint macros <strong>do not break the \u201cUndo\u201d command<\/strong>, so you can press Ctrl + Z (or \u2318 + Z on Mac) repeatedly, and it will work correctly with all macros.<\/p>\n<p>But in Excel, macros break the Undo and Redo commands unless you build a workaround into your code, which can get very complicated.<\/p>\n<p>Here\u2019s a summary of VBA in Excel vs. PowerPoint:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25628 size-full\" title=\"VBA in Excel vs. PowerPoint\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-01.jpg\" alt=\"VBA in Excel vs. PowerPoint\" width=\"1051\" height=\"503\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-01.jpg 1051w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-01-300x144.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-01-1024x490.jpg 1024w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-01-768x368.jpg 768w\" sizes=\"(max-width: 1051px) 100vw, 1051px\" \/><\/p>\n<p>Returning to the second question above \u2013 good vs. bad use cases for macros in PowerPoint \u2013 <strong>focus on<\/strong> <strong>macros that are simple to code and that automate actions you repeat <em>a lot<\/em><\/strong>.<\/p>\n<p>For example, swapping shapes is quite simple to code (5-10 minutes), and it saves you time because it\u2019s cumbersome to swap shape positions manually. Plus, it\u2019s a common task when editing presentations.<\/p>\n<p>On the other hand, it\u2019s silly to write a macro that \u201ccenters\u201d a shape vertically and horizontally on a slide because the \u201cAlign Center\u201d and \u201cAlign Middle\u201d commands already do this, and it\u2019s not especially common to center single shapes on a slide in corporate presentations.<\/p>\n<p>Something like the Table of Contents macro in our full macro package, which is based on the Slide Master and custom layouts, is in the \u201cmaybe\u201d category.<\/p>\n<p>It saves you time, but it\u2019s also complicated to code and test, and it doesn\u2019t work 100% perfectly in all cases.<\/p>\n<p>Plus, you might only add the Table of Contents when you\u2019re finished with a presentation, so this macro may be less useful than simpler shape manipulation commands.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Your_First_PowerPoint_Macro_%E2%80%9CSwap_Shapes%E2%80%9D\"><\/span><strong>Your First PowerPoint Macro: \u201cSwap Shapes\u201d<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To start writing your first macro, go to the \u201cTrust Center\u201d in PowerPoint (Alt, T, O in the PC version or \u2318 + , on Mac) and make sure the program will let you run macros:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25629 size-full\" title=\"PowerPoint Trust Center\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-02.jpg\" alt=\"PowerPoint Trust Center\" width=\"840\" height=\"685\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-02.jpg 840w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-02-300x245.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074814\/Macros-in-PowerPoint-Image-02-768x626.jpg 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25630 size-full\" title=\"PowerPoint Trust Center - Macro Security Settings\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074813\/Macros-in-PowerPoint-Image-03.jpg\" alt=\"PowerPoint Trust Center - Macro Security Settings\" width=\"840\" height=\"685\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074813\/Macros-in-PowerPoint-Image-03.jpg 840w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074813\/Macros-in-PowerPoint-Image-03-300x245.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074813\/Macros-in-PowerPoint-Image-03-768x626.jpg 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/p>\n<p>Use one of the settings above (the screens will look slightly different on the Mac) and make sure the \u201cDeveloper Toolbar\u201d in the ribbon menu is visible by going to \u201cCustomize Ribbon\u201d within the Options menu:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25631 size-full\" title=\"PowerPoint Ribbon Menu and Developer Tab\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074813\/Macros-in-PowerPoint-Image-04.jpg\" alt=\"PowerPoint Ribbon Menu and Developer Tab\" width=\"840\" height=\"685\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074813\/Macros-in-PowerPoint-Image-04.jpg 840w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074813\/Macros-in-PowerPoint-Image-04-300x245.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074813\/Macros-in-PowerPoint-Image-04-768x626.jpg 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/p>\n<p>Once you\u2019ve done this, open the VBA Editor with Alt, L, V on the PC (there is no Mac shortcut, so navigate there manually) and insert a \u201cmodule\u201d and a \u201csubroutine\u201d to write a new macro:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25632 size-full\" title=\"Macros in PowerPoint - Adding a Module and Subroutine\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074812\/Macros-in-PowerPoint-Image-05.jpg\" alt=\"Macros in PowerPoint - Adding a Module and Subroutine\" width=\"581\" height=\"501\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074812\/Macros-in-PowerPoint-Image-05.jpg 581w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074812\/Macros-in-PowerPoint-Image-05-300x259.jpg 300w\" sizes=\"(max-width: 581px) 100vw, 581px\" \/><\/p>\n<p>You can call the new module \u201cSwapShapes\u201d and add a new subroutine with the same name on the right side of the screen:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25633 size-full\" title=\"Macros in PowerPoint - VBA Subroutine\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074812\/Macros-in-PowerPoint-Image-06.jpg\" alt=\"Macros in PowerPoint - VBA Subroutine\" width=\"711\" height=\"553\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074812\/Macros-in-PowerPoint-Image-06.jpg 711w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074812\/Macros-in-PowerPoint-Image-06-300x233.jpg 300w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/p>\n<p>After you type \u201cSub SwapShapes()\u201d VBA will automatically insert the \u201cEnd Sub\u201d at the end to indicate that your macro ends there.<\/p>\n<p>With simple macros, you usually want to <strong>work with the shapes, slides, or text the user has selected<\/strong>.<\/p>\n<p>That\u2019s how this \u201cSwap Shapes\u201d macro will work: it will <em>assume<\/em> that the user has selected the shapes they want to swap, and then it will change their positions.<\/p>\n<p>First, you need to make sure <em>the user has selected shapes<\/em>, and if so, that they\u2019ve selected <em>2 shapes<\/em> rather than 1, 10, or 50 shapes:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25634 size-full\" title=\"PowerPoint VBA - Checking the User's Shape Selection\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-07.jpg\" alt=\"PowerPoint VBA - Checking the User's Shape Selection\" width=\"604\" height=\"302\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-07.jpg 604w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-07-300x150.jpg 300w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/p>\n<p>\u201cIF\u201d statements are the building blocks of all programming languages, including VBA.<\/p>\n<p>They let you check conditions, such as the selection consisting of 2 shapes, and they take actions based on whether these conditions are true or false.<\/p>\n<p>The ActiveWindow.Selection object in VBA contains whatever the user has selected (shapes, slides, text, or nothing at all), and it has \u201cproperties\u201d for things like the <em>selection type<\/em> and the <em>number of objects selected<\/em>.<\/p>\n<p>You can use the \u201cIF\u201d statements with ActiveWindow.Selection to check for these conditions.<\/p>\n<p>If you\u2019re unsure of an object\u2019s properties, you can start typing its name followed by a \u201c.\u201d so that VBA displays a list of options.<\/p>\n<p>The \u201c=\u201d operator is used for both <strong>assignments<\/strong> and <strong>equality checks<\/strong> in VBA, which is a bit confusing. But if it\u2019s part of an \u201cIF\u201d statement, as it is here, it\u2019s an equality check.<\/p>\n<p>The MsgBox command is useful for <strong>testing the code as you move along<\/strong> and ensuring the \u201cIF\u201d statements work.<\/p>\n<p>Next, you need to save the first shape\u2019s <strong>Top and Left positions<\/strong> and put them in \u201cvariables\u201d that you can refer to later.<\/p>\n<p>Here\u2019s the code:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25635 size-full\" title=\"PowerPoint VBA - Saving the Shape Positions in Variables\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-08.jpg\" alt=\"PowerPoint VBA - Saving the Shape Positions in Variables\" width=\"950\" height=\"336\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-08.jpg 950w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-08-300x106.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-08-768x272.jpg 768w\" sizes=\"(max-width: 950px) 100vw, 950px\" \/><\/p>\n<p>The \u201c=\u201d signs in the main part of the code are <strong>assignment operators<\/strong> because they\u2019re <em>not<\/em> within \u201cIF\u201d statements.<\/p>\n<p>So, they SET one shape\u2019s Left and Top coordinates to the other shape\u2019s Left and Top coordinates.<\/p>\n<p>Again, it is confusing how \u201c=\u201d can check for equality in VBA <em>and<\/em> set the value of a variable; there is no easy answer other than \u201ccontinued practice and exposure.\u201d<\/p>\n<p>The ActiveWindow.ShapeRange(1) part means: \u201cTake the <em>first<\/em> shape the user has selected on the current slide.\u201d<\/p>\n<p>You can use ActiveWindow.ShapeRange(2) to refer to the second shape, which takes us into the next part: setting the first shape\u2019s Top and Left positions to those of the second shape.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25636 size-full\" title=\"PowerPoint VBA - Changing the First Shape's Top and Left Positions\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-09.jpg\" alt=\"PowerPoint VBA - Changing the First Shape's Top and Left Positions\" width=\"814\" height=\"395\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-09.jpg 814w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-09-300x146.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074811\/Macros-in-PowerPoint-Image-09-768x373.jpg 768w\" sizes=\"(max-width: 814px) 100vw, 814px\" \/><\/p>\n<p>If you stopped here, you\u2019d have a problem because you\u2019ve now <strong>lost<\/strong> the first shape&#8217;s original Top and Left positions.<\/p>\n<p>This is why you saved them in the tempLeft and tempTop variables: by saving these original positions in variables, you can now use them to change the second shape\u2019s position.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25637 size-full\" title=\"Macros in PowerPoint: Swapping the Original Positions of the First Shape with the Second Shape\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074810\/Macros-in-PowerPoint-Image-10.jpg\" alt=\"Macros in PowerPoint: Swapping the Original Positions of the First Shape with the Second Shape\" width=\"819\" height=\"449\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074810\/Macros-in-PowerPoint-Image-10.jpg 819w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074810\/Macros-in-PowerPoint-Image-10-300x164.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074810\/Macros-in-PowerPoint-Image-10-768x421.jpg 768w\" sizes=\"(max-width: 819px) 100vw, 819px\" \/><\/p>\n<p>This code properly swaps the positions of two shapes.<\/p>\n<p>However, you can make it more efficient by using a \u201cWith\u201d statement, which also exists in Excel VBA, to remove the need to type ActiveWindow.Selection:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25638 size-full\" title=\"PowerPoint VBA and &quot;With&quot; Statements\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074810\/Macros-in-PowerPoint-Image-11.jpg\" alt=\"PowerPoint VBA and &quot;With&quot; Statements\" width=\"592\" height=\"526\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074810\/Macros-in-PowerPoint-Image-11.jpg 592w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074810\/Macros-in-PowerPoint-Image-11-300x267.jpg 300w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/p>\n<p>When you type the \u201cWith ActiveWindow.Selection\u201d line, anything that starts with a \u201c.\u201d between that and the \u201cEnd With\u201d is assumed to be part of ActiveWindow.Selection.<\/p>\n<p>So, VBA \u201ctranslates\u201d a line like this:<\/p>\n<p>tempLeft = .ShapeRange(1).Left<\/p>\n<p>Into:<\/p>\n<p>tempLeft = ActiveWindow.Selection.ShapeRange(1).Left<\/p>\n<p>You can now go into PowerPoint and test this macro with different shapes on the reference slides.<\/p>\n<p>To do this, use the Alt, L, PM shortcut in the PC version (no Mac equivalent, so navigate to Developer in the ribbon menu and click on Macros), select \u201cSwapShapes\u201d and click \u201cRun\u201d:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25639 size-full\" title=\"&quot;Shape Swap&quot; Macro Execution on a Normal PowerPoint Slide\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074809\/Macros-in-PowerPoint-Image-12.jpg\" alt=\"&quot;Shape Swap&quot; Macro Execution on a Normal PowerPoint Slide\" width=\"1012\" height=\"758\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074809\/Macros-in-PowerPoint-Image-12.jpg 1012w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074809\/Macros-in-PowerPoint-Image-12-300x225.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074809\/Macros-in-PowerPoint-Image-12-768x575.jpg 768w\" sizes=\"(max-width: 1012px) 100vw, 1012px\" \/><\/p>\n<p>As a final step, you can save this file as a <strong>macro-enabled presentation<\/strong> in the .pptm format:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25640 size-full\" title=\"Saving Macros in a Macro-Enabled PowerPoint File\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074808\/Macros-in-PowerPoint-Image-13.jpg\" alt=\"Saving Macros in a Macro-Enabled PowerPoint File\" width=\"946\" height=\"533\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074808\/Macros-in-PowerPoint-Image-13.jpg 946w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074808\/Macros-in-PowerPoint-Image-13-300x169.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074808\/Macros-in-PowerPoint-Image-13-768x433.jpg 768w\" sizes=\"(max-width: 946px) 100vw, 946px\" \/><\/p>\n<p>By doing this, you\u2019ll ensure that whoever opens the file next can still use this macro.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"The_Limitations_of_Macros_in_PowerPoint\"><\/span><strong>The Limitations of Macros in PowerPoint<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This simple exercise, while useful, also reveals a few issues with macros in PowerPoint:<\/p>\n<p><strong>1) Keyboard Shortcuts<\/strong> \u2013 There is no easy way to assign keyboard shortcuts to macros; you must activate them through the \u201cMacros\u201d menu in the Developer Toolbar.<\/p>\n<p><strong>2) Macro-Enabled Files<\/strong> \u2013 While you <em>can<\/em> save macros with the above method, it is not ideal for sharing them or making them usable across different presentations.<\/p>\n<p><strong>3) Code Constraints<\/strong> \u2013 It\u2019s simple to write code that handles <em>only 2 shapes<\/em>, but it\u2019s not immediately obvious how to extend it to manage multiple shapes.<\/p>\n<p>We could fix these issues now or explore other enhancements, but the first two points above are surprisingly complicated to solve.<\/p>\n<p>So, we\u2019ll focus on point #3 and extend this macro to make it swap multiple shapes:<\/p>\n<h2><span class=\"ez-toc-section\" id=\"An_Extension_to_Macros_in_PowerPoint_%E2%80%9CSwap_Multiple_Shapes%E2%80%9D\"><\/span><strong>An Extension to Macros in PowerPoint: \u201cSwap Multiple Shapes\u201d<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can extend this macro to swap multiple shapes with a few simple changes.<\/p>\n<p>Start by <strong>changing the variable declarations and error checks<\/strong> at the top.<\/p>\n<p>When the user selects multiple shapes, you need to <strong>save the first shape\u2019s positions<\/strong>, and you need to create a \u201ccounter variable\u201d that tracks the shape # you\u2019re currently on.<\/p>\n<p>For example, if the user has selected 10 shapes, you need to know if you\u2019re currently on shape #1, #2, #3, or #4-10 as you move through the selection and change each shape\u2019s positions.<\/p>\n<p>Also, you need to make sure the user has selected <em>more than 1 shape<\/em> \u2013 not necessarily just 2 shapes:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25641 size-full\" title=\"PowerPoint VBA - Checking to Ensure That More Than 1 Shape is Selected\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074808\/Macros-in-PowerPoint-Image-14.jpg\" alt=\"PowerPoint VBA - Checking to Ensure That More Than 1 Shape is Selected\" width=\"538\" height=\"345\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074808\/Macros-in-PowerPoint-Image-14.jpg 538w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074808\/Macros-in-PowerPoint-Image-14-300x192.jpg 300w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/p>\n<p>Next, you need to \u201cloop\u201d through all the shapes the user has selected with a \u201cFor\u201d statement.<\/p>\n<p>So, if the user has selected 10 shapes, you need to move from shape #1 through shape #10 and change the position of each shape.<\/p>\n<p>You can start by typing the syntax for this \u201cFor\u201d loop:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25642 size-full\" title=\"PowerPoint VBA - For\/Next Loop for Selected Shapes\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074807\/Macros-in-PowerPoint-Image-15.jpg\" alt=\"PowerPoint VBA - For\/Next Loop for Selected Shapes\" width=\"826\" height=\"406\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074807\/Macros-in-PowerPoint-Image-15.jpg 826w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074807\/Macros-in-PowerPoint-Image-15-300x147.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074807\/Macros-in-PowerPoint-Image-15-768x377.jpg 768w\" sizes=\"(max-width: 826px) 100vw, 826px\" \/><\/p>\n<p>For an example of how this works, continue assuming that the user has selected 10 shapes.<\/p>\n<p>In this case, you should loop through shapes #1 \u2013 #9 and set each shape\u2019s Left and Top positions to the next shape&#8217;s Left and Top positions.<\/p>\n<p>So, Shape #1 Top should become Shape #2 Top, and Shape #2 Top should become Shape #3 Top.<\/p>\n<p>When you reach shape #10, you should set its Top and Left positions to those of the <em>first shape<\/em>.<\/p>\n<p>This means you need to save shape #1\u2019s Top and Left positions before starting this loop.<\/p>\n<p>You can start by handling the case for shapes #1 \u2013 9, or \u201ceverything before the final shape\u201d:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25643 size-full\" title=\"PowerPoint VBA - Modifying the &quot;For&quot; Loop for Everything Before the Final Shape\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074807\/Macros-in-PowerPoint-Image-16.jpg\" alt=\"PowerPoint VBA - Modifying the &quot;For&quot; Loop for Everything Before the Final Shape\" width=\"941\" height=\"379\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074807\/Macros-in-PowerPoint-Image-16.jpg 941w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074807\/Macros-in-PowerPoint-Image-16-300x121.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074807\/Macros-in-PowerPoint-Image-16-768x309.jpg 768w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/p>\n<p>As the next step, you can add a special case to save the first shape\u2019s position before the \u201cFor\u201d loop and set the last shape\u2019s position equal to the first shape\u2019s:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25644 size-full\" title=\"Macros in PowerPoint: Saving the First Shape's Positions and Swapping Them in for the Last Shape\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074806\/Macros-in-PowerPoint-Image-17.jpg\" alt=\"Macros in PowerPoint: Saving the First Shape's Positions and Swapping Them in for the Last Shape\" width=\"888\" height=\"548\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074806\/Macros-in-PowerPoint-Image-17.jpg 888w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074806\/Macros-in-PowerPoint-Image-17-300x185.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074806\/Macros-in-PowerPoint-Image-17-768x474.jpg 768w\" sizes=\"(max-width: 888px) 100vw, 888px\" \/><\/p>\n<p>You can now test these changes on the reference slides and verify that this macro \u201crotates\u201d multiple shapes:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25645 size-full\" title=\"Macros in PowerPoint: Testing the Shape Swap Macro with Multiple Shapes on the Reference Slides\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074806\/Macros-in-PowerPoint-Image-18.jpg\" alt=\"Macros in PowerPoint: Testing the Shape Swap Macro with Multiple Shapes on the Reference Slides\" width=\"1011\" height=\"382\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074806\/Macros-in-PowerPoint-Image-18.jpg 1011w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074806\/Macros-in-PowerPoint-Image-18-300x113.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074806\/Macros-in-PowerPoint-Image-18-768x290.jpg 768w\" sizes=\"(max-width: 1011px) 100vw, 1011px\" \/><\/p>\n<p>Activate the macro enough times, and the shapes will return to their original positions.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Macros_in_PowerPoint_Beyond_the_Surface-Level_Detail\"><\/span><strong>Macros in PowerPoint: Beyond the Surface-Level Detail<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you\u2019ve followed the steps above, you should have a \u201cMulti-Shape Swap\u201d macro you can use to rearrange your slides.<\/p>\n<p>But this tutorial just scratches the surface; it represents ~30 minutes out of the 12-13 hours of VBA training in our <a href=\"https:\/\/breakingintowallstreet.com\/powerpoint-pro\/\" target=\"_blank\" rel=\"noopener\">full PowerPoint Pro course<\/a>.<\/p>\n<p>You can do far more with macros and VBA than simple shape manipulation \u2013 as shown in the video above, you can manipulate tables, combined table\/shape designs, and even the Language properties of entire presentations.<\/p>\n<p>And you can automate the alignment, distribution, and formatting processes in many ways, including the clever use of Drawing Guides.<\/p>\n<p>You can see the full set of macros in the course below:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25646 size-full\" title=\"Macros in PowerPoint: Full BIWS Macro Package, Part 1\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074805\/Macros-in-PowerPoint-Image-19.jpg\" alt=\"Macros in PowerPoint: Full BIWS Macro Package, Part 1\" width=\"727\" height=\"106\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074805\/Macros-in-PowerPoint-Image-19.jpg 727w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074805\/Macros-in-PowerPoint-Image-19-300x44.jpg 300w\" sizes=\"(max-width: 727px) 100vw, 727px\" \/><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25647 size-full\" title=\"Macros in PowerPoint: Full BIWS Macro Package, Part 2\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074805\/Macros-in-PowerPoint-Image-20.jpg\" alt=\"Macros in PowerPoint: Full BIWS Macro Package, Part 2\" width=\"737\" height=\"94\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074805\/Macros-in-PowerPoint-Image-20.jpg 737w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074805\/Macros-in-PowerPoint-Image-20-300x38.jpg 300w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25648 size-full\" title=\"Macros in PowerPoint: Full BIWS Macro Package, Part 3\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074804\/Macros-in-PowerPoint-Image-21.jpg\" alt=\"Macros in PowerPoint: Full BIWS Macro Package, Part 3\" width=\"519\" height=\"99\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074804\/Macros-in-PowerPoint-Image-21.jpg 519w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2023\/02\/19074804\/Macros-in-PowerPoint-Image-21-300x57.jpg 300w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/p>\n<p>You\u2019ll gain access to the full package and all the detailed tutorials as soon as you sign up for the PowerPoint Pro course:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to set up macros in PowerPoint, and you&#8217;ll get practice writing VBA code for your first macro.<\/p>\n","protected":false},"featured_media":0,"template":"","class_list":["post-25627","biws_kb","type-biws_kb","status-publish","hentry","kb_category-powerpoint"],"acf":[],"_links":{"self":[{"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/biws_kb\/25627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/biws_kb"}],"about":[{"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/types\/biws_kb"}],"wp:attachment":[{"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/media?parent=25627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}