Auto_NextSlide Help Needed

  • Thread starter Thread starter Yogi_Bear_79
  • Start date Start date
Y

Yogi_Bear_79

I have a simple test SlideShow. It contains two slides, I installed the
AutoEvents Addin. I created a module and entered the following code, but
nothing appears on the second slide. I haven't added anything to the slide
(it is blank). I had hoped this code would add a text box with that
statement in it. I looked at adding a text box manually, but found no way to
identify it. I also tried just trigering a simple MsgBox but that didn't
work either. I also tried a Selcet Case statement.

The end results will be I need to display an updated Text box on this slide
whenever it appears during the slide show loop. The text to be displayed
will be determined byVBA code.

Sub Auto_NextSlide(Index As Long)

If (Index = 2) Then
With ActivePresentation.Slide(2).Shapes("MyWeirdLittleTextBox")
.TextFrame.TextRange.Text = "Hi. I'm different now."
End If
 
I have a simple test SlideShow. It contains two slides, I installed the
AutoEvents Addin. I created a module and entered the following code, but
nothing appears on the second slide. I haven't added anything to the slide
(it is blank). I had hoped this code would add a text box with that
statement in it. I looked at adding a text box manually, but found no way to
identify it. I also tried just trigering a simple MsgBox but that didn't
work either. I also tried a Selcet Case statement.

The end results will be I need to display an updated Text box on this slide
whenever it appears during the slide show loop. The text to be displayed
will be determined byVBA code.

Sub Auto_NextSlide(Index As Long)

If (Index = 2) Then
With ActivePresentation.Slide(2).Shapes("MyWeirdLittleTextBox")
.TextFrame.TextRange.Text = "Hi. I'm different now."
End If

First, make sure that the event is triggering your macro. Add a breakpoint in
the IDE or add a msgbox or whatever works for you.

Next, it should be ActivePresentation.Slides(2) (Slides, not Slide --- my
goof, sorry about that)

You'd need to set the text box's .Name property to "MyWeirdLittleTextBox" ahead
of time for this to work.

Edit the name of a shape
http://www.rdpslides.com/pptfaq/FAQ00584.htm

And there needs to be an End With prior to End If
 
First, make sure that the event is triggering your macro. Add a
breakpoint in
the IDE or add a msgbox or whatever works for you.

Next, it should be ActivePresentation.Slides(2) (Slides, not Slide --- my
goof, sorry about that)

You'd need to set the text box's .Name property to "MyWeirdLittleTextBox"
ahead
of time for this to work.

Edit the name of a shape
http://www.rdpslides.com/pptfaq/FAQ00584.htm

And there needs to be an End With prior to End If
Ok, yeah I found a couple of my mistakes after I posted. First off from time
to time I have to go to Tools > Auto Events and turn it back on. I created a
text box from the control toolbar wit the name TextBox1, I have the
following code in a module. When the with statement is removed the MsgBox
appears. When the With statement is included I get an "invalid or
unqualified reference" on the .TextFrame.......line. So with that said I
know the trigger works, and I know it catches Slide 2, now just need to get
my Text to display in the TextBox.

Sub Auto_NextSlide(Index As Long)

If (Index = 2) Then
MsgBox "HELLO"
With ActivePresentation.Slides(2).Shapes("TextBox1")
.TextFrame.TextRange.Text = "Hi. I'm different now."
End With
End If

End Sub

I looked at the website you referenced. Is that the way I need to name the
shape, or am I ok, by creating it from the controls toolbar, and nameing it
under it's properties. I ask this because, I know of no way t create a
textbox that will stay on the slide without at lease one char in it.
 
Ok, yeah I found a couple of my mistakes after I posted. First off from time
to time I have to go to Tools > Auto Events and turn it back on. I created a
text box from the control toolbar wit the name TextBox1, I have the
following code in a module. When the with statement is removed the MsgBox
appears. When the With statement is included I get an "invalid or
unqualified reference" on the .TextFrame.......line.

Right ... it's expecting a text box shape, not an OLE control. Try it with a
standard PPT text box instead. If you really really need to use an ole text
control for some reason, let me know.

So with that said I
know the trigger works, and I know it catches Slide 2, now just need to get
my Text to display in the TextBox.

Sub Auto_NextSlide(Index As Long)

If (Index = 2) Then
MsgBox "HELLO"
With ActivePresentation.Slides(2).Shapes("TextBox1")
.TextFrame.TextRange.Text = "Hi. I'm different now."
End With
End If

End Sub

I looked at the website you referenced. Is that the way I need to name the
shape, or am I ok, by creating it from the controls toolbar, and nameing it
under it's properties. I ask this because, I know of no way t create a
textbox that will stay on the slide without at lease one char in it.

Ah. So that's why the OLE control.

You could create a regular text box but put a space character in it. Invisible
but there. Or, since you'll run this at startup before anyone sees the slide,
the text box could have any "dummy" text you like; it'll get replaced before
it's visible.
 
Steve Rindsberg said:
Right ... it's expecting a text box shape, not an OLE control. Try it
with a
standard PPT text box instead. If you really really need to use an ole
text
control for some reason, let me know.

So with that said I

Ah. So that's why the OLE control.

You could create a regular text box but put a space character in it.
Invisible
but there. Or, since you'll run this at startup before anyone sees the
slide,
the text box could have any "dummy" text you like; it'll get replaced
before
it's visible.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

Thanks for your help. The completed rough draft is below, it does what it is
intended to do. I have to clean the code some more, and add a few features,
but it does what I set out to. I needed to add a slide in my public
rollingshow that showed the days, hours, min remaining until a specifi
event. With your help, I now have this. Basically it's a countdown.
Everytime this slide is displayed it shows up to the minute how long until
an event is. I will tweak the code some more, to make it smoother, and add
a few features, for example when days reach zero, it will no longer display
days, etc...thanks again!

Sub Auto_NextSlide(Index As Long)
a = "4/21/06 11:00:00AM"

If (Index = 2) Then
b = Day(a) - Day(Now())
c = Hour(a) - Hour(Now())
d = Minute(a) - Minute(Now())

If (c < 0) Then
c = c + 24
b = b - 1
End If

If (d < 0) Then
d = d + 60
c = c - 1
End If

With ActivePresentation.Slides(2).Shapes("TextBox1")
.TextFrame.TextRange.Text = "Days " & b & ", Hours " & c & ",
Minutes " & d
End With


End If

End Sub
 
Thanks for your help. The completed rough draft is below, it does what it is
intended to do. I have to clean the code some more, and add a few features,
but it does what I set out to. I needed to add a slide in my public
rollingshow that showed the days, hours, min remaining until a specifi
event. With your help, I now have this. Basically it's a countdown.
Everytime this slide is displayed it shows up to the minute how long until
an event is. I will tweak the code some more, to make it smoother, and add
a few features, for example when days reach zero, it will no longer display
days, etc...thanks again!

See below for a suggestion on that. Aircode but it should get you close.
Sub Auto_NextSlide(Index As Long)
a = "4/21/06 11:00:00AM"

If (Index = 2) Then
b = Day(a) - Day(Now())
c = Hour(a) - Hour(Now())
d = Minute(a) - Minute(Now())

If (c < 0) Then
c = c + 24
b = b - 1
End If

If (d < 0) Then
d = d + 60
c = c - 1
End If

Dim sMsgText as String

If b > 0 then
sMsgText = "Days " & cstr(b) & ", "
Else
sMsgText = ""
End If

sMsgText = sMsgText & "Hours " & cstr(c) & ", "
sMsgText = sMsgText & "Minutes " & cstr(d)

With ActivePresentation.Slides(2).Shapes("TextBox1")
.TextFrame.TextRange.Text = sMsgText

End With
 
Steve Rindsberg said:
See below for a suggestion on that. Aircode but it should get you close.


Dim sMsgText as String

If b > 0 then
sMsgText = "Days " & cstr(b) & ", "
Else
sMsgText = ""
End If

sMsgText = sMsgText & "Hours " & cstr(c) & ", "
sMsgText = sMsgText & "Minutes " & cstr(d)

With ActivePresentation.Slides(2).Shapes("TextBox1")
.TextFrame.TextRange.Text = sMsgText

End With

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

Steve, Wanted to thank you for your help. Here is v1.0.0. I am startig a
new thread for a new feature that I want to add.. Thanks again

Sub Auto_NextSlide(Index As Long)

' Declare variables
Dim EventDate As Date, curDate As Date
Dim iSlide As Integer, days As Integer, hours As Integer, minutes As
Integer, seconds As Integer
Dim sDateFile As String
Dim sSeconds As String, sMinutes As String, sDays As String, sHours As
String, strDiff As String
Dim objFSO As Object, objTextStream As Object

' Initialize variables
curDate = Now()
sDateFile = "CountDown_DateFile.txt"
iSlide = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open test file read date
If objFSO.FileExists(sDateFile) Then ' Verify the file exists
Set objTextStream = objFSO.OpenTextFile(sDateFile, FOR_READING)

Do Until objTextStream.AtEndOfStream
EventDate = objTextStream.ReadLine
Loop

objTextStream.Close 'Close the text file
Else
' File not found do something
End If

' Index equals the slide number you want updated. For the demo this is
slide #1
If (Index = iSlide) Then
days = Day(EventDate) - Day(curDate)
hours = Hour(EventDate) - Hour(curDate)
minutes = Minute(EventDate) - Minute(curDate)
seconds = Second(EventDate) - Second(curDate)

' Calculate days
days = IIf(hours <= 0, days - 1, days)
sDays = IIf(days = 1, " Day, ", " Days, ") ' Use singular versus
plural when applicable

' Calculate hours
hours = IIf(hours <= 0, hours + 24, hours)
hours = IIf(minutes <= 0, hours - 1, hours)
sHours = IIf(hours = 1, " Hour, ", " Hours, ") ' Use singular versus
plural when applicable

' Calculate minutes
minutes = IIf(minutes <= 0, minutes + 59, minutes)
sMinutes = IIf(minutes = 1, " Minute, ", " Minutes, ") ' Use
singular versus plural when applicable

' Calculate seconds
seconds = IIf(seconds <= 0, seconds + 59, seconds)
sSeconds = IIf(seconds = 1, " Second", " Seconds") ' Use singular
versus plural when applicable

' Build display string, remove Days, &/or Hours if they are no
longer needed
If (days <= 0) Then
If (hours <= 0) Then
strDiff = minutes & sMinutes & seconds & sSeconds
Else
strDiff = hours & sHours & minutes & sMinutes & seconds &
sSeconds
End If
Else
If (hours <= 0) Then
strDiff = days & sDays & minutes & sMinutes & seconds &
sSeconds
Else
strDiff = days & sDays & hours & sHours & minutes & sMinutes
& seconds & sSeconds
End If

End If

' Display the String
With ActivePresentation.Slides(iSlide).Shapes("TextBox1")
.TextFrame.TextRange.Text = strDiff
End With

End If

End Sub

Function IIf(Condition, TrueValue, FalseValue)
If Condition Then
IIf = TrueValue
Else
IIf = FalseValue
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top