PDA

View Full Version : Need help with a slight modification in my VBA code



omar23j
07-31-2018, 11:06 AM
Hi everyone, I have a VBA code to create a countdown counter inside 4 shapes in a slide ( days, hours, minutes and seconds). I use an action button (shape) to run the macro, on mouse click.

My code is as below:


Public Sub Countdown() Dim diff As Double
Dim endDate As Date: endDate = DateSerial(2018, 11, 2)
Dim days As Integer
While 1
DoEvents
diff = endDate - Now()
days = Int(diff)
With ActivePresentation
.Slides(2).Shapes(4).TextFrame.TextRange.Text = days
.Slides(2).Shapes(6).TextFrame.TextRange.Text = Hour(diff - days)
.Slides(2).Shapes(7).TextFrame.TextRange.Text = Minute(diff - days)
.Slides(2).Shapes(8).TextFrame.TextRange.Text = Second(diff - days)
End With
Wend
End Sub

However, the problem is that this code will only work when the slide is in the 2nd position of the presentation. How could I modify the code such that this would work regardless of the position my slide in in the ppt? Any help would be appreciated.

John Wilson
08-01-2018, 12:18 AM
Maybe something like:


Public Sub Countdown()

Dim diff As Double
Dim osld As Slide
Set osld = ActivePresentation.SlideShowWindow.View.Slide
Dim endDate As Date: endDate = DateSerial(2018, 11, 2)
Dim days As Integer
While 1
DoEvents
diff = endDate - Now()
days = Int(diff)

osld.Shapes(4).TextFrame.TextRange.Text = days
osld.Shapes(6).TextFrame.TextRange.Text = Hour(diff - days)
osld.Shapes(7).TextFrame.TextRange.Text = Minute(diff - days)
osld.Shapes(8).TextFrame.TextRange.Text = Second(diff - days)

Wend
End Sub

omar23j
08-03-2018, 08:06 AM
Maybe something like:


Public Sub Countdown()

Dim diff As Double
Dim osld As Slide
Set osld = ActivePresentation.SlideShowWindow.View.Slide
Dim endDate As Date: endDate = DateSerial(2018, 11, 2)
Dim days As Integer
While 1
DoEvents
diff = endDate - Now()
days = Int(diff)

osld.Shapes(4).TextFrame.TextRange.Text = days
osld.Shapes(6).TextFrame.TextRange.Text = Hour(diff - days)
osld.Shapes(7).TextFrame.TextRange.Text = Minute(diff - days)
osld.Shapes(8).TextFrame.TextRange.Text = Second(diff - days)

Wend
End Sub

thanks!!