Is VBA the answer? Is it the RIGHT answer? Will it solve my presentation problem?
Before deciding on a VBA solution to a problem, you should understand the limits of VBA. What follows may sound negative; it's not meant that way. But it IS an honest look, from a guy who LOVES VBA, at what you can and can't expect VBA to do for your presentations.
We figure you'd much rather learn that "You can't do that" before spending weeks pounding your head against the walls learning that "You can't do that". That in turn might save you the cost (and embarassment) of planning an important presentation around VBA tricks that turn out to be impossible to use in your situation.
Where will you use your presentation?
If you plan to use the web version of PowerPoint (including viewing from within Teams), the iPhone or Android versions, VBA is out. None of them support it at all.
Security Settings
If you can assume a desktop version of PowerPoint (Windows or Mac), the next thing to consider is the security settings on the individual computers. Do you control these settings or can you persuade individual users to adjust their settings to meet your needs?
Depending on the user's macro security settings, or the settings imposed by their IT department, PowerPoint may ask the user whether to allow your VBA code to run or it may silently disable your macros altogether without even notifying the user.
In rare cases, it may simply allow your code to run with no questions asked. Buy lottery tickets. This is your lucky day.
Running on a Mac?
VBA won't work in Mac PowerPoint 2008. Period. It does work in previous and later versions.
Code That Runs Automatically
Some Office applications (Word, Excel) have a way to run VBA code automatically when the user opens a document.
PowerPoint doesn't.
An Auto_Open subroutine within an Add-in will run at the time the Add-in loads, so IF you can create an Add-in and install it on the user's computer Create an ADD-IN with TOOLBARS that run macros then
- The Add-in can respond to events - Make PPT respond to events
- It can detect things like "The user just opened a presentation".
- You could use this and some extra code to detect that "The user just opened OUR presentation" and run any other code you like in response.
Can VBA even do this?
Even if you're still with us, VBA may still not be the answer. VBA allows us to automate nearly everything that PowerPoint can do. It even allows us to do some things that PowerPoint can't do under normal user control. But PowerPoint doesn't "expose" all of its capabilities to VBA.
There are some features that a user can click with a mouse but that VBA simply can't "see". What PowerPoint doesn't expose, VBA can't control and we can't automate.
How can you tell what can and can't be controlled?
- Have a look at the rest of the VBA section of this FAQ and some of the other PowerPoint VBA sites it links to. You may find that somebody's already written code that does what you want.
- In some cases, macros recorded in Excel or Word, which still have macro recorders, can give you a clue to how a task might be accomplished.
- Microsoft Answers: The PowerPoint Support Forum is your friend. Post a detailed message outlining what you need to do and you'll have a reliable answer from one or more experienced PowerPoint coders, often within 24 hours or less.
- The PowerPoint subreddit on Reddit.com
- Programming-related sites like Stack Overflow are great resources for help with code that's not working quite right.