ActiveSlide and ActivePresentation in VBA, Auto_Open macro

C

Chip Pearson

For a client, I need to write a small PPT add-in (PPT 2003 SP2). I've never
written a PPT add-in before, but have written hundreds of Excel add-ins. My
questions are as follows:

"ActiveSlide" Does PPT have something like an "ActiveSlide" object that
refers slide that is currently active in PPT? How do you reference in VBA
code the slide that you are currently editing?

"ThisPresentation" Does PPT have something like "ThisPresentation" that
always refers to the presentation in which the running VBA code is located,
regardless of what presentation is active in PPT? In Excel, we have a
ThisWorkbook object that always refers to the workbook containing the code,
regardless of which workbook happens to be active.

If there is no "ThisPresentation" object, or some similar mechanism, how do
you programmatically assign the "OnAction" property of a standard
Office.CommandBarButton. In Excel, I'd use something like
Ctrl.OnAction = ThisWorkbook.Name & "!MacroName"

The "ThisWorkbook" refers to the workbook containing the code, not the
workbook that happens to be open. If there is no such thing, what do you
assign to the OnAction property to ensure it uses the macro in the correct
Presentation.

Finally, is there a way to run a macro whenever that presentation is opened
and closed (in the editor mode, not the slideshow mode)? In Excel, we have
the Auto_Open macro that Excel will automatically execute whenever the
workbook containing it is opened. Similarly, we have Auto_Close that will
run when the workbook is closed. Does PPT VBA have something similar? I need
to run code when my add-in is loaded. I'm starting to think that maybe I
should be writing a COM Add-In in VB6 rather than a PPA add-in.

Thanks in advance for any advice you could give.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)
 
B

Bill Dilworth

Hi Chip,

First, you need to forget 50% of what you know about Excel Macros. The hard
part is knowing which 50%.

PowerPoint uses two modes: edit mode and show mode. The objects are
different and addressing the parts within them are different.

In Edit mode:
ActivePresentation refers to the presentation that has the current
focus.
Windows(1).Selection.SlideRange(1).SlideIndex will get you to the
current slide displayed in edit view

In Show Mode:
Note: Objects in the slideshow can not be selected.
SlideShowWindows(1).View.CurrentShowPosition will get you the slide
being currently displayed

You will need to install an event trap in your add-in to detect the
presentation open event. Try these links...
**How can I get my code to run automatically when a presentation opens?
http://www.pptfaq.com/FAQ00741.htm
- and -
** PowerPoint Add-ins
http://www.pptfaq.com/FAQ00359.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

Shyam Pillai

Hi Chip,

Comments inline.
"ActiveSlide" Does PPT have something like an "ActiveSlide" object that
refers slide that is currently active in PPT? How do you reference in VBA
code the slide that you are currently editing?

Nothing native available. Check this out:

Generic function to obtain active slide in any view
http://skp.mvps.org/ppt00044.htm

"ThisPresentation" Does PPT have something like "ThisPresentation" that
always refers to the presentation in which the running VBA code is
located, regardless of what presentation is active in PPT? In Excel, we
have a ThisWorkbook object that always refers to the workbook containing
the code, regardless of which workbook happens to be active.

Nope. Create your own reference. Even if you make another presentation
active it will still reference the original one.

Dim ThisPresentation as Presentation
Set ThisPresentation = ActivePresentation

If there is no "ThisPresentation" object, or some similar mechanism, how
do you programmatically assign the "OnAction" property of a standard
Office.CommandBarButton. In Excel, I'd use something like
Ctrl.OnAction = ThisWorkbook.Name & "!MacroName"
If it is in the presentation:

Ctrl.OnAction = ThisPresentation.FullName & "!MacroName"

or

Ctrl.OnAction = ActivePresentation.FullName & "!MacroName"

If you want to reference the add-in

Ctrl.OnAction = addins("myaddin.ppa") & "!MacroName"
The "ThisWorkbook" refers to the workbook containing the code, not the
workbook that happens to be open. If there is no such thing, what do you
assign to the OnAction property to ensure it uses the macro in the correct
Presentation.

See above.
Finally, is there a way to run a macro whenever that presentation is
opened and closed (in the editor mode, not the slideshow mode)? In Excel,
we have the Auto_Open macro that Excel will automatically execute whenever
the workbook containing it is opened. Similarly, we have Auto_Close that
will run when the workbook is closed. Does PPT VBA have something similar?
I need to run code when my add-in is loaded. I'm starting to think that
maybe I should be writing a COM Add-In in VB6 rather than a PPA add-in.

You will get all the PPA information you need here:
PowerPoint add-in FAQ
http://skp.mvps.org/ppafaq.com


--
Regards,
Shyam Pillai

Animation Carbon
http://www.animationcarbon.com
 

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