Saturday, August 30, 2014

Jazz Presentation

Creating Jazz Presentations For Business

Sponsors

  • Theme Forest
  • PPT Guru

Download This Article

In this tutorial we will teach you on how to Write a Macro to enable and disable image objects (show and hide) in Microsoft PowerPoint 2007 by writing few lines of macro code using Visual basic editor.  We have also created a few slides and a small example in PowerPoint to illustrate this tutorial. We have written 2 simple macros to show and hide an laptop image in the slide during slide show mode.
You can write many simple macros like this to automate frequently done tasks and do wonders in Microsoft PowerPoint 2007.  A macro is a few lines program or set of commands which allows you to automate tasks and add functionality. This is done using  Visual Basic editor inside PowerPoint 2007.  We Have Created a Sample Presentation on how to Write a macro which can be downloaded from here. Download This Presentation

Step 1: Following steps on How to Write a Macro have been covered in earlier tutorial.

We have covered following basics on how to Write a Macro in earlier tutorial.  Click here to go to earlier tutorial

  • Save the File with Correct Extension – PowerPoint Macro-Enabled Show (pptm)
  • How to enable Developer Tab ribbon menu.
  • Steps to enable PowerPoint for Macro Programming
  • Using the macro menu to Write a Macro
  • Steps to add code using Visual Basic editor.
  • Steps to  Run the Macro.

Step 2: Create a PowerPoint Slide with Images and Buttons.

We need to create a slide with relevant images to demonstrate steps to Write a Macro for  show/Hide macros.

  • We need an image to show and hide.  We have created a Laptop image to display and hide with in a photo frame.
  • We also need 2 buttons to demonstrate the macro. One button to hide the laptop on click and the other button to show/display the laptop on click.
  • As we have disabled the mouse click( explained in Step 5 below)  during slide show we need a button to navigate to next slide.
  •  The screen shot with images are shown below.
Write a Macro -  Enable Disable the image Objects using a macro
Click on the image to see a full view

 Step 3: Writing a macro for “Display Laptop Button”

Before you start to Write a Macro you need to name the macro and open the visual basic editor.  We have covered these steps in earlier tutorial in step 4 and step 5.   Click here to go to the earlier tutorial.

  • Once you open the editor write the following code to display the laptop image. Here we have given name for  the function as DisplayLaptop.
 Sub DisplayLaptop()
 'Assign the image to a variable in VB
'The Syntax to select the image is given by ActivePresentation.Slides(<em>slide_number</em>).Shapes(<em>image_name</em>)
Set tickShp = ActivePresentation.Slides(3).Shapes("LapTop")
 'To Enable the Laptop image set the Visible property of the image to True
 tickShp.Visible = True
 End Sub
  • Once you have completed writing the macro save the macro and switch back to the slide you are working on.
  •  Next step is to attach the macro to the Display Button object. Click here (step 7)  to visit our earlier tutorial on how to  Write a Macro and attach the macro to the object.
  • Select the Display the laptop button. In the menu ribbon of PowerPoint 2007, select insert menu and click on action button. Select the macro, in our case it is DisplayLaptop.
  • Also you can attach a sound file by checking the Play Sound check box.
  •  Click okay.
Write a Macro -  Enable Disable the image Objects using a macro

Click on the image to see a full view

Step 4: Writing a macro for “Hide Laptop Button”

We have covered the basics of  How to Write a a Macro in earlier tutorial in step 4 and step 5

  • open the Visual basic editor and the  write the following code to hide the laptop image. Here we have given name of the function as HideLaptop.
 Sub HideLaptop()
 'Set tickShp Variable to Point to the slide and to the laptop image
 Set tickShp = ActivePresentation.Slides(3).Shapes("LapTop")
 'To Hide the Laptop image set the variable value to False
 tickShp.Visible = False
 End Sub
  • Once you have completed writing the macro save the macro and switch back to the slide you are working on.
  •  Next step is to attach the macro to the Hide Laptop Button object. Click here (step 7)  to visit our earlier tutorial on how to Write a Macro and   attach the macro to the object.
  • Select the Hide the laptop button. In the menu ribbon of PowerPoint 2007, select insert menu and click on action button. Select the macro, in our case it is HideLaptop.
  • Also you can attach a sound file by checking the Play Sound check box.
  •  Click okay.

Step 5: Testing the 2 Macro (HideLaptop and DisplayLapTop)

As both the macro is ready we need to run the macro and test the macro.  Before you run and test the slide you need to do one more step.  The slide should go to the next slide only when you click on the next button and click in any other part of the slide should be disabled. Do the following three steps below.

  • Select Slide show from the ribbon menu,
  • Select Setup Slide show
  • Select the radio button for “Browsed at the kiosk (full screen)”.  The details are shown in the image below.
Write a macro - Enable Disable Macro in PowerPoint

Click on the image to see a full view

To Test the macro

  • Run the Presentation in Slide Show Mode.
  • Click on the Hide the Laptop button to Hide the Laptop image which is inside the photo frame.
  • Click on the Display the Laptop button to display the Laptop image which is inside the photo frame.
  • If you have attached a Sound file, you should also be able to hear the sound.

We have done lot of research in Google and Amazon.com site and have given you below few excellent books on how to Write a Macro with Visual basic Application for Microsoft PowerPoint.

1. Powerful PowerPoint for Educators: Using Visual Basic for Applications to Make PowerPoint Interactive
2. Mastering VBA for Office 2010
3. Office VBA Macros You Can Use Today: Over 100 Amazing Ways to Automate Word, Excel, PowerPoint, Outlook, and Access
4. PowerPoint 2007: The Missing Manual

Hope you enjoyed the tutorial and have understood how to Write a Macro for hiding and displaying image objects in PowerPoint 2007.

Rate this Post
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (Average: 10.00 out of 10)
Loading ... Loading ...

Leave a Reply