Automating a macro

G

Guest

I have written a PowerPoint macro that I would like to run when a new
presentation is started using the template containing the macro. I have
declared an object variable in a class module, but apparently I need to
automate the initialization of the declared object from another module.

I have tried listing the code in the App_NewPresentation subroutine, but
that doesn't work. My macro, shown below, installs a control in the Frames
context menu. Selecting the control should run the SecondSlide macro, which
is located in a module. The macro itself works as intended, when run from a
module, but I need to automate it so that the context menu is modified as
soon as a new presentation is created. Can this be done?

Set myControl = CommandBars("Frames").Controls _
.Add(Type:=msoControlButton, Before:=1) ' Add new control at start of
Frames menu.
With myControl
.Caption = "Select Second Slide" ' Define caption.
.OnAction = "SecondSlide" ' Identify macro to run.
End With

What am I overlooking?
 
B

Bill Dilworth

While you can create and save macros in POT files, they are not imported
into the presentation that uses them (unlike Word and Excel). You should
create an add-in with the macros that adds a new control.

Create an ADD-IN with TOOLBARS that run macros
http://www.pptfaq.com/FAQ00031.htm


--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
vestprog2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com
..
 
S

Steve Rindsberg

I have written a PowerPoint macro that I would like to run when a new
presentation is started using the template containing the macro. I have
declared an object variable in a class module, but apparently I need to
automate the initialization of the declared object from another module.

PPT won't run code automatically other than from an Add-in's Auto_Open and
Auto_Close subroutines.

You'll probably need to write an addin that loads at startup, installs an event
handler, traps the new presentation event or possibly a different event, and
tests the current presentation to determine whether it's based on your template
or not, then acts accordingly.
 
S

Steve Rindsberg

While you can create and save macros in POT files, they are not imported
into the presentation that uses them (unlike Word and Excel).

We interrupt this program for a bit of slightly topic-askew entertainment:

They're not imported. Unless they are.

Let's say you have a POT with macros in it called DoesTOO.pot

File, New, click from Design Template under Designs, choose DoesToo.
You get a macro warning but even if you enable macros, you get no macros.
I think somebody in Roswell might have suggested that feature; Earthling
logic? Nuh-uh.

But do File New and click "On my computer" under Templates, choose DoesToo and
you get the same macro warning. And true to its name, this time it does TOO
include macros.

When you apply DoesTOO to an existing presentation, it does not.
When you start a new presentation based on DoesToo, it does. Too.

Older versions of PPT approach this in slightly different ways and sow
confusion in different directions.

And in no case will any of them run any of the code automatically.

So as you say ... (and herewith we return you to our regularly scheduled
tomfoolery)
 

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