View Full Version : Executing Code in Powerpoint
aussieolie2
10-10-2002, 03:01 PM
Does any body know how do I get Powerpoint to execute some code automatically when it loads the slide that contains the code?
Basically I am trying to get it to update the date as soon as it loads the particular slide,
Is it like 'on load' etc.. ?!??!!?!?!?!?!?!?!?
Any suggestions as how do I execute my code automatically when the slide loads????
Thanks Mate,
Olie
Paul Komski
10-13-2002, 07:46 PM
I have done very little with VB in PP, but the relevant sub "may be" object_activate (with object being the correct slide reference - however that is written).
Could you not get what you need from setting the date field in the View Headers/Footers. I'm pretty sure you can define the date - or use the current date - and set it for one specific or all slides. To position the field you would use View Master.
Hope that is of some use.
aussieolie2
10-14-2002, 11:12 AM
For some reason, I cannot find or get the standard pieces of code (on_load, object load etc......) to execute my code when a particular slide loads, I press the play button and it works fine (only when the cursor is on the same line of the code???), how can i do this automaically???
Thanks,
Olie
Paul Komski
10-14-2002, 08:29 PM
The PowerPoint Slides are not set up with Events apparently. Individual controls (ActiveX from the Toolbox) do have some and might do the job for you. Even their events are somewhat limited but a GotFocus event might do the trick for you. Set the tabs order so that your control would pick up the focus by default, if that is possible to do.
It is possible to set up some Event Handlers (there are more of them in PP 2000/XP than 97). I have only got this far, being unused to PP, and the help files are difficult to follow with no good examples that I could find.
In a NEW CLASS MODULE say called CLASS1
Paste the following Declaration at the top:-
Public WithEvents App As Application
Then select App from the DropDown List of the Left combo
Then select the event you want from the Right combo
You might choose SlideShowBegin (from the list) and I just put in a message box so that it looks like:-
Private Sub App_SlideShowBegin(ByVal Wn As SlideShowWindow)
msgbox "KICK OFF SLIDE SHOW HERE"
End Sub
THEN paste into the top of any other non-class module:-
Dim X As New CLASS1
Sub InitializeApp()
Set X.App = Application
End Sub
Then from the menu bar of the Modules run the above sub and save the "Application" Macro. Running a sub like this (which is what I guess you were doing already shows that the code is OK) but it takes another event procedure or macro to activate it.
BEFORE you run the Slide Show run the above "Application" Macro from the Presentation MenuBar.
You should get the "KickOff" message before the SlideShow starts.
I would hope to set the relevant text box on the relevant slide(s) to the value(s) you need instead of just displaying a message box at start up - but that is as far as I have got so far. Found it the hardest Office App to program so far.
You might get further ideas or help from Google Groups (http://groups.google.ie/groups?q=powerpoint+events&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search) and there must be loads of PowerPoint Forums/Newsgroups in addition.
Paul Komski
10-15-2002, 10:56 AM
It took me a wee while to sort out modules from macros in PP since it is a bit new to me, but I think the following should work; you may need at least PP2000.
If your code is running OK from the module window, ensure that the sub(s) are not Private and they will then appear as Macros named something like SlideNo.NameOfSub
Then just replace the MsgBox "KickOff etc" line that I wrote above with your own SlideNo.NameOfSub combination. I use MsgBoxes very freely, especially when developing an app, since they let you know where you are in your code - so leaving it there and just adding a second line of code will always remind you that the SlideShowBegin Routine has been "activated".
For example on Slide7 I have a TextBox3 and on the module for Slide7 there is a (non-private) sub:-
Public Sub EnterDateInTextBox()
Me.TextBox3 = Format(Date, "dd/mm/yyyy")
End Sub
The following is the modified sub in the Class Module, which needs to be run before the Slide Show is started and will place the current date with dd/mm/dddd format in the relevant Slide so that it is updated when that Slide is reached.
Private Sub App_SlideShowBegin(ByVal Wn As SlideShowWindow)
MsgBox "SLIDE SHOW STARTING"
Slide7.EnterDateInTextBox
End Sub
Next, to make life a little bit easier, from the PP Window Record a Macro by clicking on the relevant commands to Initialize and then Run the Slide Show; it will be placed in a new module and look something like this:-
Sub RunSlideShow()
Application.Run "'powerpoint2.ppt'!Slide1.InitializeApp"
With ActivePresentation.SlideShowSettings
.ShowType = ppShowTypeSpeaker
.LoopUntilStopped = msoFalse
.ShowWithNarration = msoTrue
.ShowWithAnimation = msoTrue
.RangeType = ppShowAll
.AdvanceMode = ppSlideShowManualAdvance
.PointerColor.SchemeColor = ppForeground
.Run
End With
SlideShowWindows(Index:=1).View.Next
SlideShowWindows(Index:=1).View.Next
SlideShowWindows(Index:=1).View.Next
End Sub
Finally On the Tools menu, click Customize, and then click the Commands tab and under Categories, click Macros. Then just drag the RunSlideShow Macro (or whatever you called it) onto a toolbar to make it easy to operate from a single click.
Hope that helps. Let us know if you have further problems.
aussieolie2
10-16-2002, 10:36 AM
Thanks Paul for your help,
Right now Im in the middle of something that needs being done, but further on in the week I will experimemt with this code and see where it gets me.
Basically I wanted to have the date on a slide, automatically update (see below) and I haven got around to trying these on load etc.. codes.
---CODE---
Private Sub TextBox2_Change()
Me.TextBox2.Text = Format(Date, "Long Date")
End Sub
---ENDOFCODE---
Thats the only code that works so far, when i get a change i would love to try the code you have recommended.
Thank you so much for your help,
Regards,
Olie
Paul Komski
10-16-2002, 07:09 PM
FYI The modules and macros in Access are distinct entities and are "called" using different protocols. In PP etc any non private procedure in a module just becomes a macro. Vice versa, creating a macro in PP will write the code for an underlying procedure in a new module.
Thus if you change your "Private Sub TextBox2_Change()" to just "Sub TextBox2_Change()" it should then appear as a Macro called SlideX.TextBox2_Change
That macro can then be executed by directly running it (from run in a module window) or else by "calling it"; just put the line SlideX.TextBox2_Change into another event procedure (or any procedure) or you could add it as a macro (that is as an action) to an ActionButton (obtained from the SlideShow menu items). If the text in the textbox is actually changed (a bit like an afterupdate in Access) then that too should execute the code. That seems a messy event to use for your purpose; a gotfocus or dblclick event might be more appropriate.
aussieolie2
10-22-2002, 01:17 PM
This is great, if you want events to start automatically with the presentation this add-on works great. Check it out:
http://www.mvps.org/skp/autoevents.htm
Also for good addons see also:
http://www.mvps.org/skp/download.htm
Olie :D :D
vBulletin v3.6.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.