Consulting

Results 1 to 6 of 6

Thread: Macro only works after viewing the sorce code

  1. #1
    VBAX Newbie
    Joined
    Dec 2008
    Posts
    4
    Location

    Macro only works after viewing the sorce code

    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:
    [vba]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 Sub[/vba]Note: 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
    [vba]Call OnSlideShowPageChange[/vba] 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.

  2. #2
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    Your first line needs to be:
    [vba]Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)[/vba]
    Last edited by Cosmo; 12-18-2008 at 02:49 PM.

  3. #3
    VBAX Newbie
    Joined
    Dec 2008
    Posts
    4
    Location
    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.

  4. #4
    VBAX Newbie
    Joined
    Dec 2008
    Posts
    4
    Location
    Still doesn't work for some reason. I have even stripped my code down to a simple test if the event is firing.

    [vba]Sub OnSlideShowPageChange(ByVal ssw As SlideShowWindow)
    MsgBox ("Test")
    End Sub[/vba]
    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?

  5. #5
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    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

  6. #6
    VBAX Newbie
    Joined
    Dec 2008
    Posts
    4
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •