PPT2000: How to Create a PowerPoint Add-In
ID: Q222737
|
The information in this article applies to:
-
Microsoft PowerPoint 2000
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, 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/overview/overview.asp NOTE: The following macro examples only work from within the PowerPoint application. Visual Basic for Applications macros are not supported by the Microsoft PowerPoint Viewer. For additional information, please see the following article in the Microsoft Knowledge Base:
Q230746 PPT: Viewer: Presentation Macros Don't Run
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 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 Office Assistant on the Standard toolbar.
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.
REFERENCESFor more information about using the sample code in this article, please
see the following article in the Microsoft Knowledge Base:
Q212536
OFF2000: How to Run Sample Code from Knowledge Base Articles
Additional query words:
9.00 ppt9 vba vbe ppt2k powerpt vba2k ppt9.0 ppt2000 program programming
Keywords : kbcode kbmacro kbprg kbdta kbdtacode kbpptvba
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
|