In VBA How can I detect slide switching

  • Thread starter Thread starter John Crawford
  • Start date Start date
J

John Crawford

I have a standard presentation first page that I use with all of my
presentations. However it is quite boring. Using VBA I randomly place
lines and shapes on the slide. Works great.
Now the problem. When I move forward in the presentation, the
function continues to run. I have set it up as an infinate loop, so I
know why it is still running. I have tried to find some event in the
presentation that I can use to stop the loop. However I cannot find one.
Since a click, or 'page down' do the switching, there must be a way.
If anyone can point me in the right direction it would be appreciated.
While I am on the same topic, is there a way to automatically start
a macro when the presentation starts? Currently, to start my display, I
am using a macro linked to an object on teh slide. Again it works ok,
but an automated process would be best.
I am using Powerpoint/Office 2000.
Any help would be appreciated.
Thanks in advance
John Crawford
 
I have a standard presentation first page that I use with all of my
presentations. However it is quite boring. Using VBA I randomly place
lines and shapes on the slide. Works great.
Now the problem. When I move forward in the presentation, the
function continues to run. I have set it up as an infinate loop, so I
know why it is still running. I have tried to find some event in the
presentation that I can use to stop the loop. However I cannot find one.
Since a click, or 'page down' do the switching, there must be a way.

You can implement an event handler:

Make PPT respond to events
http://www.rdpslides.com/pptfaq/FAQ00004.htm

but it might be simpler to add a button to your first slide. Set its action
setting to Run Macro and have it run this:

Sub MoveOn()
ContinueLooping = False
ActivePresentation.SlideShowWindow.View.GoToSlide(2)
End Sub

Include this in the declarations section of the module with your main loop
subroutine:

Public ContinueLooping as Boolean

Change your main loop to include:

ContinueLooping = True

While ContinueLooping
' do your stuff
Wend
While I am on the same topic, is there a way to automatically start
a macro when the presentation starts? Currently, to start my display, I
am using a macro linked to an object on teh slide. Again it works ok,
but an automated process would be best.

With an event handler loaded in an addin, yes. Otherwise, no.
 
Steve:
Thank you very much. I had thought of using an object (actually the
same object that started the process, but checking the state of a global
variable to see whether to start or stop the process.), but thought
there must be another way.
I had also seen some information on the Class module and was trying
to figure out how to use it. I will look at the samples and see how to
make them work. There may be other things that would be useful to have,
and understand.
John Crawford
 
Steve:
Thank you very much. I had thought of using an object (actually the
same object that started the process, but checking the state of a global
variable to see whether to start or stop the process.), but thought
there must be another way.

There probably are other ways around it ... you could set a tag on one of the
slides, for example. That'd have the advantage that if your code crashed, the
value of a global might be lost, where the tag would be consistent.
 
Steve and Shyam:
I solved the problem. I used the pptEvent sample to understand how
to set up the class module. I then added code for the SlideShowNextSlide
event (it seems tio be called by next, previous, and Go). I use that to
check a global variable, and if set (Animation is active) I stop
animation. I use an object on teh first slide to start the animation.
Since the animation changes the presentation, I am asked at the end
of the PPshow if I want to save changes. I changed the SlideShowEnd
event to set the presentation .Saved to true, that way I do not get the
message, and the presentation just ends.
Thank you both for pointing me in the right direction, and the
excelent example.
John Crawford
 
Superb, John. Most of the credit goes to Shyam for his excellent event example
code/essay.
 
Back
Top