add-in auto_open problem

M

Mike Williams

PowerPoint 2007 SP2
Pardon me if this is an unbelievably mangled problem, where it
shouldn't be. I have Excel and Word VBA experience, but none in PP.

I have a macro (UpdatePath, below) that works, that I want to run any
time I open a ppt file. Actually, it's a little more complicated. I
found info online that suggested I need an auto_open and an auto_close
procedure around it, so I added that and tweaked it. I saved the code
as an add-in (*.ppam). I loaded the add-in. It doesn't fire.

Can someone please point me towards how to fix this, or else point me
to a How-To that works? THANKS. The 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 = "Add Filename to Handout Footer"

' Connect the menu choice to your macro. The OnAction property
' should be set to the name of your macro.
NewControl.OnAction = "UpdatePath"

End Sub

Sub UpdatePath()

' Macro to add the path and file name to each slide's footer.
Dim PathAndName As String
Dim FeedBack As Integer

' Place a message box warning prior to replacing footers.
FeedBack = MsgBox( _
"This Macro replaces any existing text that appears " & _
"within your current footers " & Chr(13) & _
"with the presentation name and its path. " & _
"Do you want to continue?", vbQuestion + vbYesNo, _
"Warning!")

' If no is selected in the dialog box, quit the macro.
If FeedBack = vbNo Then
End
End If

PathAndName = LCase(ActivePresentation.Name)
With ActivePresentation.HandoutMaster.HeadersFooters
With .Footer
.Text = PathAndName
End With
End With

End Sub

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 = "Add Filename to Handout Footer"
Then

' Check to see whether action setting is set to
ChangeView.
If oControl.OnAction = "UpdatePath" Then

' Remove the command from the menu.
oControl.Delete
End If
End If
Next oControl

End Sub
 
M

Mike Williams

actually, I'm now not sure I created the add-in properly. It's
loaded, but apparently is empty or blank. Back to the drawing board.
 
M

Mike Williams

OK, a little more carefully.
The add-in tab shows the addin loaded, with the new button. Clicking
on the button runs the code properly.
What doesn't happen is that I want the code to run automatically
whenever PP starts up, or whenever a new PP file is opened.
 
M

Mark

OK, a little more carefully.
The add-in tab shows the addin loaded, with the new button.  Clicking
on the button runs the code properly.
What doesn't happen is that I want the code to run automatically
whenever PP starts up, or whenever a new PP file is opened.

You need to add code to the specific application events that you want.
Check the help file for the Application.PresentationOpen Event and the
Application.NewPresentation Event. I don't believe there is an event
that you can have fire whenever the application starts up.
 
M

Mark

You need to add code to the specific application events that you want.
Check the help file for the Application.PresentationOpen Event and the
Application.NewPresentation Event. I don't believe there is an event
that you can have fire whenever the application starts up.

I should amend this to say that the Auto_Open sub will run when the
application starts if the add-in is loaded. But it will also run again
if the add-in is unloaded and loaded again.
 
M

Mike Williams

The Auto_Open routine will run whenever PPT starts, as you've seen.

If you want it to run whenever a new presentation opens, you need to
add event handling to the add-in.

There's more on that here:

Make your VBA code in PowerPoint respond to eventshttp://www.pptfaq.com/FAQ00004.htm

==============================
PPT Frequently Asked Questionshttp://www.pptfaq.com/

PPTools add-ins for PowerPointhttp://www.pptools.com/

So it looks like I should put the code from the procedure I want to
run in the Auto_Open procedure. Doh!
 
M

Mike Williams

Dang. It seems like it should be so simple. As you can see from the
code below, I'm trying to automatically include a certain footer on
all my handouts, and there's no date-like feature for it. I tried
using Auto_Print in the add-in code, but that didn't work.

Yes and no.  Auto_Open only fires when the add-in loads (ie, when PPT first
starts up).  It won't fire in response to opening presentations.

==============================
PPT Frequently Asked Questionshttp://www.pptfaq.com/

PPTools add-ins for PowerPointhttp://www.pptools.com/

=================

Sub Footer_Text()
' Macro to add the path and file name to each slide's footer.
Dim PathAndName As String
Dim FeedBack As Integer
PathAndName = LCase(ActivePresentation.Name)
With ActivePresentation.HandoutMaster.HeadersFooters
With .Footer
.Text = PathAndName
End With
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top