How to create a PowerPoint add-in in PowerPoint 2000 (222737)
The information in this article applies to:
- Microsoft PowerPoint 2000
This article was previously published under Q222737 For a Microsoft PowerPoint 97 version of this
article, see
163461. SUMMARY 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.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. NOTE: The following macro examples work only in PowerPoint. Visual
Basic for Applications macros are not supported by the Microsoft PowerPoint
Viewer. For additional information, click the following article number to view
the article in the Microsoft Knowledge Base: Step 1 - Create the Code for the Add-In To create the code for the add-in, follow these steps:
- Start PowerPoint and create a blank presentation.
- On the Tools menu, point to Macro, and then click Visual Basic Editor.
- In the Visual Basic Editor, click Module, on the Insert menu.
- 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.
Step 2 - Create the Auto_Open Macro 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
Step 3 - Create the Auto_Close Macro 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 that 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
Step 4 - Create the .ppa File To create the .ppa file, follow these steps:
- 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, follow
these steps:
- Click Options on the Tools menu, and then click the Editor tab.
- Click to clear or select the Auto Syntax Check check
box, and then click OK.
If this option is currently selected, skip to step
2.
- Save the presentation.
- On the File menu, click Close and Return to Microsoft PowerPoint.
- On the File menu, click Save As.
- Select Presentation (*.ppt) in the Save As Type list.
- Name the presentation, and then click Save.
Your add-in code is now saved in the presentation.
- Create the .ppa file.
- On the File menu, click Save As.
- Select PowerPoint Add-In (*.ppa) in the Save As Type list.
- 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.
Step 5 - Load the Add-In To load the add-in, follow these steps:
- On the Tools menu, click Add-Ins.
- Click Add New.
- 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.
- 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 about 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. For additional information,
click the article number below to view the article in the Microsoft Knowledge
Base: 222685 PPT2000: How to Auto Load a PowerPoint Add-In
Step 6 - Unload the Add-In To unload an add-in, follow these steps :
- On the Tools menu, click Add-Ins.
- 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.
Step 7 - Protecting Your Add-In with a Password When you save a presentation as an add-in, PowerPoint does not
protect your source code. You can protect your code with a password. To do
this, follow these steps: NOTE: You must protect your project with a password before you save
the add-in. - On the Tools menu, click VBAProject Properties, and then click the Protection tab.
- Click to select the Lock Project For Viewing check box.
- Under Password To View Project Properties, type the password you want in the Password and Confirm Password boxes.
- Click OK. A password is now required to view your source code.
REFERENCES For more information about how to use the sample code in
this article, click the article number below to view the article in the
Microsoft Knowledge Base: 212536
OFF2000: How to Run Sample Code from Knowledge Base Articles
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbAutomation KbVBA kbAddIn kbcode kbdtacode kbhowto kbmacro kbProgramming KB222737 |
---|
|