Share via

How to code a PowerPoint counter?

Anonymous
2014-12-09T21:52:54+00:00

Here's my problem:

I just found out how to make simple codes myself, maybe a couple days ago. I don't have much experience.

I am making a presentation In PowerPoint, and it involves a "Counter". Every time I run the macro on the button, label 1 in slide 2 (Dark gray) should go from 0 to 1, 1 to 2 and so on. I also have a second label (Light gray).  If the caption of label 1 is equal to the caption of label 2 (If it is equal to 1), the slideshow should go to slide 3. Otherwise, it goes to slide 4. I tried coding this myself, but I guess I don't know enough about the VBA language.

This is what I tried.

Sub Counter()

Slide2.Label1.Caption = (Slide2.Label1.Caption) + 1

'I got this from a video, and I have a feeling this won't work.

If Slide2.Label1.Caption = Slide2.Label2.Caption Then

ActivePresentation.SlideShowWindow.View.GotoSlide 3

Else

ActivePresentation.SlideShowWindow.View.GotoSlide 4

'I also have a feeling this is wrong.

End sub

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Steve Rindsberg 99,166 Reputation points MVP Volunteer Moderator
    2014-12-11T02:49:30+00:00

    Thought it might. The code looked ok otherwise.

    It's a good habit to get into ... compiling the code after any change and before trying to run it, especially if you're going to be running it in slide show, where PPT just silently eats any errors and leaves you wondering why there were no burps.  ;-)

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-12-10T20:31:43+00:00

    Wow, thanks! It works perfectly now.

    Was this answer helpful?

    0 comments No comments
  3. Steve Rindsberg 99,166 Reputation points MVP Volunteer Moderator
    2014-12-10T16:26:44+00:00

    You're missing an End If just before End Sub.  That will prevent it from compiling, and in slide show view, if the macro doesn't compile, you get no warning; it simply doesn't work.

    Was this answer helpful?

    0 comments No comments