Using events in PPT VBA

  • Thread starter Thread starter charlie oppenheimer
  • Start date Start date
C

charlie oppenheimer

Hello all,

I am trying to trigger a procedure on the ShowShowBegin
event. But, I cannot understand the help "Using Events
with the Application Object" for doing so. Does anyone
have any code (not an add-in) that you could share so I
can see how to do this?

Thanks,
Charlie
 
This is copied directly from the VBA help file. It's is a bit much, for a
beginner, but here you go...


Using Events with the Application Object

To create an event handler for an event of the Application object, you need
to complete the following three steps:

Declare an object variable in a class module to respond to the events.
Write the specific event procedures.
Initialize the declared object from another module.
Declare the Object Variable
Before you can write procedures for the events of the Application object,
you must create a new class module and declare an object of type Application
with events. For example, assume that a new class module is created and
called EventClassModule. The new class module contains the following code.

Public WithEvents App As Application
Write the Event Procedures
After the new object has been declared with events, it appears in the Object
list in the class module, and you can write event procedures for the new
object. (When you select the new object in the Object list, the valid events
for that object are listed in the Procedure list.) Select an event from the
Procedure list; an empty procedure is added to the class module.

Private Sub App_NewPresentation()

End Sub
Initializing the Declared Object
Before the procedure will run, you must connect the declared object in the
class module (App in this example) with the Application object. You can do
this with the following code from any module.

Dim X As New EventClassModule
Sub InitializeApp()
Set X.App = Application
End Sub
Run the InitializeApp procedure. After the procedure is run, the App object
in the class module points to the Microsoft PowerPoint Application object,
and the event procedures in the class module will run when the events occur.


B
===============
Please spend a few minutes checking out www.pptfaq.com This link will
answer most of our questions, before you think to ask them.

Change org to com to defuse anti-spam, ant-virus, anti-nuisance
misdirection.
 
Dear B,

Thanks for posting a response to my question. The
references were really
helpful. What I still can't figure out is how to get a
macro to run
automatically when a presentation starts, without
requiring everyone who
views it to install an add-in first. Any ideas?

Thanks,
Charlie
 
Only a ppa (add-in) will fire automatically when program loads, sorry.

What is it you want to do from this macro? When does it need to be done by
(before show, after first slide...)? Oh, and always, what version of
PowerPoint?

B
===============
Please spend a few minutes checking out www.pptfaq.com This link will
answer most of our questions, before you think to ask them.

Change org to com to defuse anti-spam, ant-virus, anti-nuisance
misdirection.
 
B,

PowerPoint 2K. Scenario: Have simulation written in VBA
that runs on one slide that goes into many different
presentations. The simulation runs progressively further
each time a user clicks a button on the slide called "next
day". Each click of "next day" runs another iteration of
the simulation. When they are done with the sim, they
just advance to the next slide. I want to have the
simulation go to initialized state when someone arrives on
the slide (in slideshow mode of course), without the need
to have them press a special "reset" or "start" button.

And while I'm at it, I'd also like the simulation to not
cause the "changed" flag to be set in PPT so that when the
user tries to close PPT, it doesn't ask them if they want
to save.

Charlie
 
Last question first...

ActivePresentation.Saved = msoTrue
will make PowerPoint skip the 'Do you want to save changes' screen (until a
subsequent change is made). Friendly warning: it is very easy to lose an
hours worth of coding when this line of code is used. Manually save often.


First question ...

You could...
....add a transparent clear rectangle over the whole slide
....set the action setting for the shape to mouse over, run 'Reset_code'
macro
....have the 'Reset_code' remove the transparent box

It would not fire the code until the user moved the mouse (to make it
appear).

I would also ...
....have an action button to advance to the next slide (disable advance on
click), so that it would reset the slide to default position and replace the
transparent box with the action setting.

Sounds like a fun project.


B
 
Back
Top