Power Point VBA code

mse330

Well-known Member
Joined
Oct 18, 2007
Messages
687
Office Version
365
Platform
Windows
Hi all,

I am working on a presentation & I want to show a number that decreases (like a counter) & after looking on some YouTube videos I think it could be achieved much easier with the VBA loop. However, I am having an issue with the below code where it will start with 10 (in presentation mode) but will not show the number 9, 8, 7 … etc. but the screen will freezes until the loop ends & shows me 1 at the end. Any idea what am I doing wrong or how to achieve my goal ?


Code:
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
For X = 10 To 1 Step -1
    ActivePresentation.Slides(1).Shapes("Rectangle 3").Fill.ForeColor.RGB = RGB((X * 10), (X * 10), (X * 10))
    ActivePresentation.Slides(1).Shapes("Rectangle 3").TextFrame2.TextRange.Characters.Text = X
    T = Timer
    Do While Timer - T < 0.5
    Loop
Next
End Sub
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,751
Office Version
2016, 2013, 2011, 2010, 2007
Platform
Windows
I suggest you look at the timer bit
T=timer then you test timer-to which would have the same values giving an almost zero result so while loop will never execute
Have you looked at the wait function
 

mse330

Well-known Member
Joined
Oct 18, 2007
Messages
687
Office Version
365
Platform
Windows
Thank you jimrward for your reply. I have developed the some code in excel & it is working as intended. The reason I use timer & not wait function is I don't want to wait 1 second for a number in the loop, I want it to be a bit faster

Code:
Sub Count_Down()
For X = 10 To 1 Step -1
    With Cells(1, 1)
        .Font.Color = vbWhite
        .Interior.Color = RGB((X * 10), (X * 10), (X * 10))
        .Value = X
    End With
    T = Timer
    Do While Timer - T < 0.5
    Loop
Next
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,102,344
Messages
5,486,307
Members
407,538
Latest member
kbendelac

This Week's Hot Topics

Top