PowerPoint Programming

Everything about PowerPoint programming including VBA, VSTO, and more.

See Also:
PowerPoint and Presenting Notes
PowerPoint and Presenting Glossary

« Older Entries «



Wednesday, July 16, 2025, posted by Geetesh Bajaj at 9:30 am

Ever tried copying an object in PowerPoint and found it refuses to sit still when pasted? Instead of landing neatly atop the original—like a twin returning to its bunk bed—it drifts off like a rebellious balloon, as shown in Figure 1, below. This default offset paste behavior can be especially annoying when working with precise layouts, animations, or rotational effects that demand pixel-perfect placement. That’s where VBA steps in like a backstage ninja, letting you paste objects exactly where you want—no nudging required.

Paste in Place Offset
Figure 1: Pasted object is offset from the original

Before you unleash your PowerPoint-fueled sorcery, here’s the first step: you need to know how to run VBA scripts in PowerPoint. Think of it like discovering a hidden trapdoor backstage — once you find it, you can rig all kinds of magical effects.

It’s not complicated, but it’s a bit like finding the remote that controls the presentation behind the curtain. Once you’re in, you’ll meet VBA — Visual Basic for Applications — a kind of techy whisperer that tells PowerPoint to behave exactly the way you want. Like pasting objects exactly in place instead of letting them wander like lost ducks.

Then, you will use this code. Explore the code a bit though.

Option Explicit
 
Sub PasteInPlace()
 
Dim sld As Slide
Dim shp As Shape
 
Set sld = Application.ActiveWindow.View.Slide
 
Dim y As Single
Dim x As Single
 
y = ActiveWindow.Selection.ShapeRange.Top
x = ActiveWindow.Selection.ShapeRange.Left
 
Windows(1).Selection.Copy
ActivePresentation.Slides(sld.SlideIndex).Shapes.Paste
 
ActivePresentation.Slides(sld.SlideIndex).Shapes(ActivePresentation.Slides(sld.SlideIndex).Shapes.Count).Top = y
ActivePresentation.Slides(sld.SlideIndex).Shapes(ActivePresentation.Slides(sld.SlideIndex).Shapes.Count).Left = x
End Sub

Alright, you’ve just dropped that magical VBA code into PowerPoint’s secret command center — the VBA Editor. Now, close that window and return to your slide deck like a superhero stepping back from their gadget lab.

But hold up! Before you start testing your macro-powered wizardry, save your file — and not just any old way. You need to use the PowerPoint Macro-Enabled Presentation format — the one with the .PPTM extension. If you save as any of the other file formats, PowerPoint will offer to remove the macros, and then, of course, the code to paste in place will not work! See our PowerPoint File Formats page to learn about these file formats.

Now that your macro is ready for action, it’s time to flip the switch — like starting the popcorn machine before movie night.

  1. Switch to the right slide deck: Open (or hop over to) the PowerPoint presentation that contains those embedded videos. Think of it like switching TV channels to the one with the good stuff.
  2. Summon your macro: Press Alt + F8 — it’s like shouting “Accio macro!” (yes, Harry Potter fans, that was for you). Doing so opens the Macro dialog box, where your code lives.
  3. Set your macro GPS: In the box next to Macro in: choose All open presentations, as shown highlighted in red within Figure 2, below. This is kind of like telling PowerPoint, “Look everywhere, not just in this one drawer.”
  4. Run the PasteInPlace macro
    Figure 2: Run the PasteInPlace macro
  5. Pick and launch your spell: Click the macro name — PasteInPlace — and then hit Run, highlighted in blue within Figure 2, above. It’s like pressing the play button on a very specific playlist that only includes magic tricks.

We ran this code using PowerPoint 365 for Windows, and it behaved like a well-trained puppy — responsive, obedient, and surprisingly agile. Now here’s the twist: we haven’t tried it on PowerPoint 365 for Mac yet. It might work like a charm… or throw a tantrum like a vending machine that eats your coins. Only a brave Mac user can tell us! So, if you give this VBA code a spin on your Mac — and it does work (or even if it flat-out rebels) — we’d love to hear about it. Drop us a comment below like you’re giving Yelp feedback for a secret recipe.

Windows users, you’re not off the hook either! If you spot quirks, bonus tricks, or even just want to say “Yep, this worked!” — share your thoughts too. Community wisdom beats lone-wolf coding any day!

Many thanks to Marcin Mikuszewski who suggested some changes to the code. Thanks for helping this community, Marcin.


You May Also Like: Use VBA in PowerPoint, Even if You Can’t Program for Nuts | Resources on PowerPoint Programming and VBA

Filed Under: Programming
Tagged as: , , ,

Comments Off on VBA Code: Paste in Place


Thursday, February 9, 2023, posted by Geetesh Bajaj at 9:30 am

John Korchok
John Korchok has been creating reliable branded Office templates and web sites for more than 20 years. He is certified as a Microsoft Office Specialist Master, is an award-winning technical writer and is skilled in programming VBA, JavaScript for PDF and web, HTML, CSS, and PHP. John is a moderator for Microsoft Answers and a volunteer at Stack Overflow, providing answers for Word and PowerPoint for Windows and macOS. He currently works for Brandwares in metropolitan New York.

In this conversation, John talks about his new Icon Gallery add-in for PowerPoint.

Read the rest of this entry »

Filed Under: Interviews
Tagged as: , , ,

Comments Off on Icon Gallery Add-in for PowerPoint: Conversation with John Korchok


Wednesday, May 4, 2022, posted by Geetesh Bajaj at 9:30 am

Have you created or inherited a PowerPoint file that contains a linked video file that you want to share with others? Wouldn’t it be easier if you could send your recipients a PowerPoint file that contained all the videos as part of the file, rather than send them the linked videos separately?

Linked video

Read the rest of this entry »

Filed Under: Programming
Tagged as: , , , ,

Comments Off on VBA Code: Change Linked Videos to Embedded?


Wednesday, May 20, 2020, posted by Geetesh Bajaj at 9:30 am

By John Korchok

We looked at the basics of XML programming in our Introducing XML Hacking in Microsoft Office post. Now, let us take this concept further. Let’s start hacking some XML with a simple project: setting the default table text size.

This article assumes you have a suitable text editor installed. Mac users should also read the XML Hacking: Editing in OS X post.

When you insert a new table in PowerPoint, the default table text size is 18 points. Using XML hacking, we can set this to whatever point size the designer prefers. You can also set the text to appear in all caps. Following the previous post’s instructions, add .ZIP to the file ending and unzip the file. Look for the ppt folder and open it:

Look for the PPT folder
Read the rest of this entry »

Filed Under: XML
Tagged as: ,

3 Comments


Wednesday, May 13, 2020, posted by Geetesh Bajaj at 9:30 am

By John Korchok

With the introduction of Office 2007, Microsoft changed the basic file format that underlies Word, PowerPoint, and Excel. Instead of the proprietary and mostly undocumented format that ruled from Office 97 to Office 2003, Microsoft made a smart decision and switched to XML. This is tagged text, similar in structure and concept to HTML code with which you may already be familiar.

XML opens up a world of possibilities for automated document construction, but that’s a topic for another day. The everyday relevance is that if a Word or PowerPoint file isn’t doing what you need it to do and there are no tools in the program for the job, we can now dive in and edit the file ourselves. If you’re a point-and-click user, this is probably not thrilling. But if you’re a hacker at heart, a midnight coder, or just a curious tinkerer, you can do some cool stuff.

Inside a simple Word file
Read the rest of this entry »

Filed Under: XML
Tagged as: ,

Comments Off on Introducing XML Hacking in Microsoft Office


« Older Entries «





Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.

Plagiarism will be detected by Copyscape

© 2000-2025, Geetesh Bajaj - All rights reserved.

since November 02, 2000



-->