Powerful PowerPoint for Educators

Using Visual Basic for Application to Make PowerPoint Interactive

by David M. Marcovitz

More Tricks

This space is dedicated to VBA tricks that were not included in the book. The examples here might not be explained as well as those in the book or as fully developed or tested as other examples on this site, but they will show you how to do things beyond what is in the book.

Click on a link below to download an example in the format you choose.

Examples are available in two formats: Zip (*.zip) format and text format (the VBA code only).

Click on a an example to download it. These examples will not run over the Web, they will not run with the PowerPoint Viewer, they will not run while compressed, and they will not run with macros disabled.

These examples have not been updated for the Second Edition. Many of them have been incorporated into the new edition. Others might not work perfectly in newer versions of PowerPoint.

# Description Zip Version Text Version
1

Someone wanted to create a random clock exam. I didn't make it into an exam, but I did the hard part of getting a random time to display on the screen as a random clock

ClockHands.zip
(61KB)
ClockHands.txt
(6KB)
The following examples have not been updated for the Second Edition. Many of them have been incorporated into the new edition. Others might not work perfectly in newer versions of PowerPoint.
2

Another example that writes to a file: Ask for a name, address, and city/state/zip. Write that information to an existing file named addressFile.txt

fileAddresses.zip
(7KB)
fileAddresses.txt
(1KB)
3

Several people have wanted a printable page that prints without the Print button. This is particularly helpful if you have modified the Printable Page (see Example 7-9), to create a certificate of completion rather than a list of questions answered. This example is exactly like Example 7-9, except that when you print, the buttons do not show up on the printout.

PrintCertificate.zip
(17KB)
PrintCertificate.txt
(6KB)
4

This example allows you to click on a shape to make it bigger. Clicking again will return it to its original size.

Bigger and Smaller.zip
(8KB)
Bigger and Smaller.txt
(1KB)
5

This is some code to move shapes around on the screen. The first slide has a single shape. Click on the "Move To 5,5" button, and the rectangle will be moved to the top left of the screen (5,5). Click on the "Ask and Move" button, and you will be asked where you want to move. Slide 2 has a small checker board with a couple of checkers. Click on a checker, and it will turn green. Click on any empty square on the board, and the green checker will move there. This isn't that smart and would need a lot more work to create a decent checkers game.

MovingExample.zip
(11KB)
MovingExample.txt
(2KB)
6

Someone asked me about using HTML code in the text of PowerPoint. He wanted VBA to be able to take simple tags, such as <B> and <I>, to convert text to bold and italic. This example does that.

HTMLize.zip
(10KB)
HTMLize.txt
(3KB)
7

My daughter is older now, and the "Ella Can Read" example (see Examples 8.16 and 8.17 are too simple for her even with some fun additions such as many longer questions with harder words and a way for her to choose only the hard questions. This is my crazy idea of an answer (yes, she reads books, and we limit her time on the computer as well). This example creates a branching story that randomly branches. The VBA simply looks for numbers in shape 2 on the current slide and randomly picks which slide number to jump to. If there is only one choice, it jumps to that slide. If there are no choices, it says "The End" and quits. While this could all be done in PowerPoint, I found it easier to do in Word, so the Word file is my story (it's fairly silly and needs more work). It uses the style Heading 1 for the text followed by Heading 2 for the choices. This is easily loaded into PowerPoint by choosing Slides From File from the Insert menu. The template (MakeStory.pot) has the VBA built-in, so write the story, open the template, delete the first blank slide if your version of PowerPoint creates it, and insert the slides from the Word file. Writing a coherent branching story is definitely the hard part.

MakeStory.zip
(53KB)
MakeStory.txt
(1KB)
8

Here are a couple of ideas for Drag and Drop, including a link to information about a new program from Hans Hofler, the original Drag and Drop creatore

http://www.deadgekko.co.uk/downloads.htm


http://tinyurl.com/bdpopa
9

Can you make a crossword puzzle with PowerPoint and VBA? Someone named Mel asked me this so I made this sample as a proof of concept. It really contains no new VBA tricks, but it combines them for an interesting effect.

Crossword.zip
(15KB)
Crossword.txt
(4KB)
10

Several people have asked about making a hover button (you know the buttons that change when you hover over them on the Web). It might be easier to do without VBA, but here is a VBA solution.

HoverButton.zip
(15KB)
HoverButton.txt
(5KB)
11

Many examples in the book involve hiding and showing shapes. The problem is that while you are developing a presentation, shapes tend to be hidden before the procedure that shows them works. This presentation includes a simple procedure to show every shape in a presentation. Copy the ShowItAll procedure and run it any time you need to get all your hidden shapes back.

ShowAll.zip
(9KB)
ShowAll.txt
(1KB)
12

While this occasionally happens on any computer, it happens more frequently on a Mac in PowerPoint 2004: you make a link to a file and then move the presentation and the link breaks. Most of the time, this is your fault. If you want the link to persist, the file has to be in the same folder as the PowerPoint presentation, and when the presentation gets moved, the linked file has to move as well. For more information about this, read this entry from the PPT FAQ: http://www.pptfaq.com/FAQ00155.htm. However, sometimes, this is not your fault. You have done everything right, and the link still breaks. I have seen this frequently on Macs. What happens is that PowerPoint inserts the link with the full path to the file. If you move the file, the path changes, but it doesn't change in PowerPoint. In Windows, you can use the FixLinks add-in to fix problem, but it doesn't work on a Mac (at least for version 2004). This quick and dirty code will let you create relative links. It does not error checking, and you have to type the name of the file, but it works. The code works just like Example 8.7. It works in Normal View, not Slide Show view. You have to select an object or some text and then use Alt-F8 to run one of the macros. One macro will create a link from an object (i.e., if the thing you want to click on is a button or shape). The other will create a hypertext link (if the thing you want to click on is text).

PathlessLink.zip
(9KB)
PathlessLink.txt
(1KB)
13

I have gotten a couple of questions about random flashcards so I have made a simple example. The zip file is done in PowerPoint 2007, but is should work in any version. However, if you just want code, copy it into your module from the text file. You will need a first slide with a button that is tied to RandomNext, a last slide with whatever you want on it, and pairs of slides in the between (the random code will break if there is anything else or if the first and last slides are missing). For each pair of slides, the first one needs a button to go to the next slide, and the second one needs a button linked to RandomNext. It will go through the pairs of slides in random order until it has gone through them all, and then it will jump to the last slide. You can have as many pairs of slides (each one representing a flash card) as you like. One day, I'll get ambitious and rewrite the random code to use a more sophisticated flashcard algorithm (like Corrective Feedback Paradigm by Marty Siegel), but that is too much effort for now.

Flashcards.zip
(48KB)
Flashcards.txt
(4KB)
14

Someone wanted a simple mechanism for keeping score by simply clicking on buttons to add an amount to a score text box. This doesn't use anything that isn't described in the book, but it is a neat application. Also, note that with a minor modification, the code can be adjusted to have the score text box be on a different slide than the current slide (see the section This Slide or Another Slide in the book). This example was created in 2010, but it should work in any version. On a Mac, it would probably need a call to refresh the slide (see "Refreshing after Hiding and Showing in Mac PowerPoint 2004" in the Errata section on this Web site).

AddToScore.zip
(44KB)
AddToScore.txt
(4KB)

This page was created by Dr. David M. Marcovitz.
Last updated: August 29, 2012