ID: Q163461
The information in this article applies to:
This article describes how to create an add-in for Microsoft PowerPoint using Microsoft Visual Basic for Applications. The sample macro (Sub procedure) adds a command to the Tools menu to allow you to change your view to slide sorter view if you are not already in slide sorter view.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/refguide/default.asp
1. Start PowerPoint and create a blank presentation.
2. On the Tools menu, point to Macro, and then click Visual Basic Editor.
3. In the Visual Basic Editor, click Module on the Insert menu.
4. Type the following code in the Module window.
NOTE: You can substitute your code for the following code.
Sub ChangeView()
' Check to see whether a presentation is open.
If Presentations.Count <> 0 Then
If ActiveWindow.ViewType <> ppViewSlideSorter Then
ActiveWindow.ViewType = ppViewSlideSorter
End If
Else
MsgBox "No presentation open. Open a presentation and " _
& "run the macro again.", vbExclamation
End If
End Sub
NOTE: A line that is preceded by an apostrophe (') introduces a
comment in the code. Comments are provided to explain what the code
is doing at a particular point in the procedure. This text is
optional and may be excluded from your code.
The Auto_Open macro stores initialization code for your add-in and it is automatically executed when the add-in is loaded by PowerPoint. The following code, adds a command (Change to Slide Sorter) to the Tools menu that executes your add-in code.
Sub Auto_Open()
Dim NewControl As CommandBarControl
' Store an object reference to a command bar.
Dim ToolsMenu As CommandBars
' Figure out where to place the menu choice.
Set ToolsMenu = Application.CommandBars
' Create the menu choice. The choice is created in the first
' position in the Tools menu.
Set NewControl = ToolsMenu("Tools").Controls.Add _
(Type:=msoControlButton, _
Before:=1)
' Name the command.
NewControl.Caption = "Change to Slide Sorter"
' Connect the menu choice to your macro. The OnAction property
' should be set to the name of your macro.
NewControl.OnAction = "ChangeView"
End Sub
The Auto_Close macro is executed when an add-in is unloaded by PowerPoint. The Auto_Close macro stores your clean-up code. The following code removes the command you added to the Tools menu in the "Create the Auto_Open Macro" section of this article.
Sub Auto_Close()
Dim oControl As CommandBarControl
Dim ToolsMenu As CommandBars
' Get an object reference to a command bar.
Set ToolsMenu = Application.CommandBars
' Loop through the commands on the tools menu.
For Each oControl In ToolsMenu("Tools").Controls
' Check to see whether the comand exists.
If oControl.Caption = "Change to Slide Sorter" Then
' Check to see whether action setting is set to ChangeView.
If oControl.OnAction = "ChangeView" Then
' Remove the command from the menu.
oControl.Delete
End If
End If
Next oControl
End Sub
1. On the Debug menu, click Compile VBAProject.
If your code has compile errors, you will not be able to create the
add-in.
NOTE: This step is only required if the Auto Syntax Check option
in the Visual Basic Editor is not selected. To turn this option on or
off, use these steps:
a. Click Options on the Tools menu, and then click the Editor tab.
b. Clear or select the Auto Syntax Check check box, and then click OK.
If this option is currently selected, skip to step 2.
2. Save the presentation.
a. On the File menu, click Close and Return to Microsoft PowerPoint.
b. On the File menu, click Save As.
c. Select Presentation (*.ppt) in the Save As Type list.
d. Name the presentation, and then click Save.
Your add-in code is now saved in the presentation.
3. Create the .ppa file.
a. On the File menu, click Save As.
b. Select PowerPoint Add-In (*.ppa) in the Save As Type list.
c. In the File Name box, type a name for your add-in, and then click
Save.
Typically, PowerPoint add-ins are placed in the c:\Program Files\
Microsoft Office\Office folder. However, you can choose another
folder if you want.
1. On the Tools menu, click Add-Ins.
2. Click Add New.
3. In the Add New PowerPoint Add-In dialog box, select the add-in file you
created in the "Step 4 - Create the PPA File" section. Click OK.
4. In the macro warning message box, click Enable Macros.
NOTE: If you received an add-in file from an unknown source, you should
click Disable Macros.
The Auto_Open macro now executes.
For information on how to use the PowerPoint object model to load add-ins,
click the Office Assistant, type "Loaded property," click Search, and then
click to view "Loaded Property."
NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Visual Basic Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q120802
TITLE : Office: How to Add/Remove a Single Office Program or
Component
Use the following steps to unload an add-in:
1. On the Tools menu, click Add-Ins.
2. From the Available Add-Ins list, select the add-in you want to unload,
and then click Unload or Remove.
When you click Unload, the add-in is unloaded but it remains on the
Available Add-Ins list. When you click Remove, the add-in is unloaded
and it is removed from the Available Add-Ins list.
The Auto_Close macro now executes.
For information on how to use the PowerPoint object model to load add-ins,
click the Office Assistant, type "Loaded property," click Search, and then
click to view "Loaded Property."
NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Visual Basic Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q120802
TITLE : Office: How to Add/Remove a Single Office Program or
Component
When you save a presentation as an add-in, PowerPoint does not protect your source code. You can protect your code with a password, using the following steps.
NOTE: You must protect your project with a password before you save the add-in.
1. On the Tools menu, click VBAProject Properties, and then click the
Protection tab.
2. Click to select the Lock Project For Viewing check box.
3. Under Password To View Project Properties, type the password you want in
the Password and Confirm Password boxes.
4. Click OK.
A password is now required to view your source code.
For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q163435
TITLE : VBA: Programming Resources for Visual Basic for
Applications
Additional query words: 8.00 ppt8 vba vbe addin addins macppt mac_ppt ppt98
powerpt
Keywords : kbcode kbmacro kbprg kbdta kbdtacode kbpptvba
Version : WINDOWS:97; MACINTOSH:98
Platform : MACINTOSH WINDOWS
Hardware : MAC x86
Issue type : kbhowto
Last Reviewed: May 17, 1999