PDA

View Full Version : Macro only works after viewing the sorce code



efarley
12-18-2008, 02:00 PM
Hey guys I am writing a macro for PowerPoint at work that when the first slide plays it sets a Custom Document Property, which is used in a C# environment later to test if the slide show has been viewed or not. Here is the code I am using:
Sub OnSlideShowPageChange()
'If ssw.View.CurrentShowPosition = ssw.Presentation.SlideShowSettings.StartingSlide Then
If ActivePresentation.CustomDocumentProperties.Count > 0 Then
ActivePresentation.CustomDocumentProperties("point2").Delete
End If
Dim i As Integer
i = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
If i <> 1 Then Exit Sub
ActivePresentation.CustomDocumentProperties.Add Name:="point2", LinkToContent:=False, Type:=msoPropertyTypeString, Value:="True"
End SubNote: I commented out the first line in the sub as I think that is a better way to test the first slide, but sense I can't get this working with the code that was provided on this site I'm not using it yet until I resolve this problem.

Here is the problem, If I go into the Developer tab and click Visual Basic to view/edit the code and then click Play the show this works fine; but if the code has not been viewed then the code does not run at all. What am I missing here guys? I don't see how there is a difference in code execution as to whether or not the editor is opened. This code is currently inside its own Module, I have also tried a Class Module but that didn't work even with the code editor open.

So with further tinkering I have found that I can also get this code to run if I click Macros and select Run for OnSlideShowPageChange, which will give me an error because there is no active slide show, and on running the slide show the macro works fine. Why would this only work after the code has been viewed or I manually attempt to execute it?

I also read on here that OnSlideShowPageChange can be quirky and it might be necessary to call it manually. but when I added the line
Call OnSlideShowPageChange No code runs even where it did before and I am given an error "Invalid outside procedure". I am currently looking into this further but any advice would be fantastic. I understand this error is because the call is not inside a sub of its own, but then I have to call THAT sub from another Sub to call OnSlideShowPageChange which defeats the whole point of calling the sub OnSlideShowPageChange.

Cosmo
12-18-2008, 02:28 PM
Your first line needs to be:
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)

efarley
12-18-2008, 04:15 PM
I had that for awhile and was still unsuccessful. I will try it again tomorrow, but in the meantime any other suggestions would be great.

efarley
12-19-2008, 06:10 AM
Still doesn't work for some reason. I have even stripped my code down to a simple test if the event is firing.

Sub OnSlideShowPageChange(ByVal ssw As SlideShowWindow)
MsgBox ("Test")
End Sub
But I still get the same effect, this doesn't fire unless it is done manually the first time, is there anyway I can manually call this procedure when the show loads?

Cosmo
12-19-2008, 06:53 AM
Ok, now I'm seeing the same results you are. From what I can tell, it won't run until the Visual Basic editor is opened. I never used 'OnSlideShowPageChange' before this.

You could create an event handler to do what you want. Have a look at this link:
http://www.pptfaq.com/FAQ00004.htm

efarley
12-22-2008, 12:10 PM
I tried that and it still didn't work, I even tried installing his example and nothing happened. BUT I have developed a work around of my own that does work! YAY go me haha. For anyone else that might have this problem here is what I did. First I looked and found which event is trigger in Power Point when the user clicks the "From Beginning" (SlideShowFromBeginning) and used a program (Office 2007 Custom UI Editor) to repurpose this event to run a macro I wrote. Once this macro is fired OnSlideShowPageChange works fine, no call to it is needed. This worked for my needs because the user is playing a show from the beginning, if they were able to start it any of the other ways you would just need to repurpose the events that are related to them.

Thanks for the help Cosmo! I appreciate it.