Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PowerPoint Animation with VBA 1

Status
Not open for further replies.

misscrf

Technical User
Jun 7, 2004
1,344
US
I posted this in the Office section, but was asked to post here instead.

I have been working on some PowerPoint animation that works like a quiz. A list box has possible answers, and depending on the answer they choose, a textbox has a certain value and color to it. I would also like to animate the text box so it looks slick. Here is the code I have so far:

CODE
Code:
Private Sub ListBox1_Click()
If ListBox1 <> "" Then
answer = ListBox1

If answer = "My Answer 1" Then
txtExample = "That's part right, but there's more!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(128, 0, 255)
'Color - Purple
txtExample.BackColor = RGB(0, 255, 255)
'Color - Cyan
txtExample.BorderColor = RGB(0, 0, 0)
'Color - Black

ElseIf answer = "My Answer 2" Then
txtExample = "That's kinda sorta right, but there's some more!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(0, 191, 255)
'Color - Deep Sky Blue
txtExample.BackColor = RGB(173, 255, 47)
'Color - Green Yellow
txtExample.BorderColor = RGB(255, 20, 147)
'Color - Deep Pink

ElseIf answer = "My Answer 3" Then
txtExample = "There's more, but that is part of it!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(240, 128, 128)
'Color - Light Coral
txtExample.BackColor = RGB(216, 191, 216)
'Color - Thistle
txtExample.BorderColor = RGB(218, 165, 32)
'Color - Goldenrod

ElseIf answer = "My Correct Answer 4" Then
txtExample = "WOHOOOOOO!!!!! You Got it Right!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(208, 32, 144)
'Color - Violet Red
txtExample.BackColor = RGB(245, 245, 220)
'Color - Beige
txtExample.BorderColor = RGB(0, 250, 154)
'Color - Green
End If
End If
End Sub

All of this works, and now I jsut also want to add a line for each answer like

docmd.animation = fly in left

or

txtExample.entrance = (flyin, Left)
lol
I know that's not right, but I am guessing someone out there might know what would be right. Is there also a list of the vba names for the animations for entrance and emphasis, etc?


Besides this, I am working on the end of the powerpoint, sending an email to a static address letting them know that this user has completed the presentation. I have it working with the following code. The only problem is that Outlook asks for permission to send the email. This is on an internal network, and I really want to put something in the code to trust the email or to say yes to the permission for the user. One big problem is that you are in presentation mode, and the permission box has a habit of going behind the presentation, then you can't see it. Please take a look at the code if you can and let me know if you have any thoughts.

Code:
Private Sub CommandButton1_Click()
Dim objOutlook As Object 'Outlook.Application
Dim objOutlookMsg As Object 'Outlook.MailItem
Dim objOutlookRecip As Object 'Outlook.Recipient

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0)

With objOutlookMsg
'   Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add("me@email.com")
    objOutlookRecip.Type = 1
    ' Set the Subject and Body of the message; save and send message
    .Subject = "Harrassment Presentation Completed"
    ' this could be from a variable if you have one
    .Body = Me.txtExample & " has successfully completed the Presentation on " & Date
    'this was code I tried to trust the email - didn't work
    .Save
'    objMailItem.Save
'Set objSafeMail = CreateObject("Redemption.SafeMailItem")
'objSafeMail.Item = objMailItem
'objSafeMail.Send

    .Send
End With
Set objOutlook = Nothing

End Sub
Thank you!

misscrf

It is never too late to become what you could have been ~ George Eliot
 
Yep, and nothing at all happens.

This is my whole code, which I have been trying to work with, besides the code you showed me.

Code:
Private Sub ListBox1_Click()
Dim oShp As Shape
If ListBox1 <> "" Then
answer = ListBox1

 For Each oShp In ActivePresentation.Slides(1).Shapes
      With oShp
        If UCase(Left(.Name, 4)) = "txtExample" Then
            With oShp.AnimationSettings
                .Animate = msoTrue
                .AnimationOrder = 1
                 .AdvanceMode = ppAdvanceModeMixed
                 With .PlaySettings
        .PlayOnEntry = True
        .HideWhileNotPlaying = True
         End With
                .TextLevelEffect = ppAnimateLevelNone
                .EntryEffect = ppEffectBoxIn
                .AnimateTextInReverse = msoFalse
            End With
        End If
      End With
    Next


If answer = "Test1" Then
txtExample.Visible = True
txtExample = "That's part right, but there's more!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(128, 0, 255)
'Color - Purple
txtExample.BackColor = RGB(0, 255, 255)
'Color - Cyan
txtExample.BorderColor = RGB(0, 0, 0)
'Color - Black

ElseIf answer = "Test2" Then
txtExample.Visible = True
txtExample = "That's kinda sorta right, but there's some more!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(0, 191, 255)
'Color - Deep Sky Blue
txtExample.BackColor = RGB(173, 255, 47)
'Color - Green Yellow
txtExample.BorderColor = RGB(255, 20, 147)
'Color - Deep Pink


ElseIf answer = "Test3" Then
txtExample.Visible = True
txtExample = "There's more, but that is part of it!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(240, 128, 128)
'Color - Light Coral
txtExample.BackColor = RGB(216, 191, 216)
'Color - Thistle
txtExample.BorderColor = RGB(218, 165, 32)
'Color - Goldenrod


ElseIf answer = "Test4" Then
txtExample.Visible = True
txtExample = "WOHOOOOOO!!!!! You Got it Right!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(208, 32, 144)
'Color - Violet Red
txtExample.BackColor = RGB(245, 245, 220)
'Color - Beige
txtExample.BorderColor = RGB(0, 250, 154)
'Color - Black
End If
End If
End Sub

There is no reason this shouldn't work is there?


misscrf

It is never too late to become what you could have been ~ George Eliot
 
Problem with Left(....., 4) and Upper case

Try this
Code:
Private Sub ListBox1_Click()
    Dim oShp As Shape, [b]sPrefix As String[/b]
    If ListBox1 <> "" Then
    answer = ListBox1[b]
    sPrefix = "TXTEXAMPLE"  'testing UCase - Upper Case
    [/b]
     For Each oShp In ActivePresentation.Slides(1).Shapes
          With oShp
            If UCase(Left(.Name, [b]Len(sPrefix)[/b])) = [b]sPrefix[/b] Then
                With oShp.AnimationSettings
                    .Animate = msoTrue
                    .AnimationOrder = 1
                     .AdvanceMode = ppAdvanceModeMixed
                    With .PlaySettings
                        .PlayOnEntry = True
                        .HideWhileNotPlaying = True
                    End With
                    .TextLevelEffect = ppAnimateLevelNone
                    .EntryEffect = ppEffectBoxIn
                    .AnimateTextInReverse = msoFalse
                End With
            End If
          End With
    Next
'........the rest doesn't matter

Skip,

[glasses] [red][/red]
[tongue]
 
I get the following error:

Run-time error '-2147188160 (80048240)':
AnimationSettings (unknown member) : Invalid request.


Thank you.

misscrf

It is never too late to become what you could have been ~ George Eliot
 


On what statement?

Hit the debug.

Do a Watch Window on oShp.Name and post the value.

Skip,

[glasses] [red][/red]
[tongue]
 



How to use the Watch Window as a Power Programming Tool faq707-4594

Skip,

[glasses] [red][/red]
[tongue]
 
It highlights .EntryEffect = ppEffectBoxIn when I debug, and says .EntryEffect = 257

it also says .Name = "txtExample"

misscrf

It is never too late to become what you could have been ~ George Eliot
 



BTW, .PlaySettings errors on me because a TextBox is not a media type that gets playsettings, it seems, or am I wrong?

So I commented out the PlaySettings and I get NO annimation at all using your code.

Skip,

[glasses] [red][/red]
[tongue]
 
Yes, I took the playsettings out too. What I mean by it says .EntryEffect = 257 is that when I hit debug and hover my mouse over .EntryEffect, thats what it says on the tip text.

misscrf

It is never too late to become what you could have been ~ George Eliot
 



did you replace ppEffectBoxIn with 3074?

I did get your code to work. There is ONE annimation on the click.

Skip,

[glasses] [red][/red]
[tongue]
 
yes, I did that anyway, but still get the debug error. This is what I have now, to check:

Code:
Private Sub ListBox1_Click()
 Dim oShp As Shape, sPrefix As String
    If ListBox1 <> "" Then
    answer = ListBox1
    sPrefix = "TXTEXAMPLE"  'testing UCase - Upper Case
    
     For Each oShp In ActivePresentation.Slides(1).Shapes
          With oShp
            If UCase(Left(.Name, Len(sPrefix))) = sPrefix Then
                With oShp.AnimationSettings
                    .TextLevelEffect = ppAnimateLevelNone
                    .EntryEffect = 3074
                    .AnimateTextInReverse = msoFalse
                End With
            End If
          End With
    Next

If answer = "Test1" Then
txtExample.Visible = True
txtExample = "That's part right, but there's more!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(128, 0, 255)
'Color - Purple
txtExample.BackColor = RGB(0, 255, 255)
'Color - Cyan
txtExample.BorderColor = RGB(0, 0, 0)
'Color - Black

ElseIf answer = "Test2" Then
txtExample.Visible = True
txtExample = "That's kinda sorta right, but there's some more!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(0, 191, 255)
'Color - Deep Sky Blue
txtExample.BackColor = RGB(173, 255, 47)
'Color - Green Yellow
txtExample.BorderColor = RGB(255, 20, 147)
'Color - Deep Pink


ElseIf answer = "Test3" Then
txtExample.Visible = True
txtExample = "There's more, but that is part of it!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(240, 128, 128)
'Color - Light Coral
txtExample.BackColor = RGB(216, 191, 216)
'Color - Thistle
txtExample.BorderColor = RGB(218, 165, 32)
'Color - Goldenrod


ElseIf answer = "Test4" Then
txtExample.Visible = True
txtExample = "WOHOOOOOO!!!!! You Got it Right!"
txtExample.SpecialEffect = fmBorderStyleSingle
txtExample.ForeColor = RGB(208, 32, 144)
'Color - Violet Red
txtExample.BackColor = RGB(245, 245, 220)
'Color - Beige
txtExample.BorderColor = RGB(0, 250, 154)
'Color - Black
End If
End If
End Sub

I also tried making If UCase(Left(.Name, Len(sPrefix))) = "txtExample"

Since that's what the tip text says when I debug.

Thank you.

misscrf

It is never too late to become what you could have been ~ George Eliot
 




Step thru the loop and see if it errors on the very first shape or some other shape.

Skip,

[glasses] [red][/red]
[tongue]
 
I took a picture of where it errors:
entryeffect.jpg


does this make any sense?

misscrf

It is never too late to become what you could have been ~ George Eliot
 



Please explain the process of events leading up to the ListBox click that runs this code. Be painfully detailed, like

Step 1 - Open the PPT file
etc

Skip,

[glasses] [red][/red]
[tongue]
 
OK, I open the powerpoint, I put it into slide presentation mode, so that the controls will work. Then I choose an option from the listbox. Before trying to animate this all, the textbox worked well. It would change colors and all, it just didn't animate which would look so cool. lol

That's it.

I found something else too. When I was doing that debugging, I hovered over oshp at the point where it says: For Each oShp In ActivePresentation.Slides(1).Shapes

The hover text and immediate window says oshp = nothing.

What? lol

Does that tell us something? (I am thinking it does lol)

When I ran your code to determine my shapes, they came up as combobox1, listbox1, txtExample, command1 and command2.

It does see them. :-(

misscrf

It is never too late to become what you could have been ~ George Eliot
 



oShp will be Nothing until the code enters the loop.

I have been executing the code BEFORE the slide show starts. I think that I need to add a listbox and run the code within the show. Stand by.

Skip,

[glasses] [red][/red]
[tongue]
 



For ease of purpose I used a CommandButton on the one and only Slide in my ppt.

The CommandButton ran the code to completion and nothing happened on the slide.

I then hit the -> advance slide - NOTHING
I hit it again AND got the animation.
Hit it again and the show closed.

I still have no answer for the error...
[tt]
Run-time error '-2147188160 (80048240)':
AnimationSettings (unknown member) : Invalid request.
[/tt]
I do not get that error. Try Help/Detect & repair. If that does not help, try reloading PowerPoint. There may be a library missing.

Skip,

[glasses] [red][/red]
[tongue]
 
I did a detect and repair, but I am still having issues. I tried to use a different method, because I found code that did this in another way. It still doesn't like it, but I wonder if this might be a new avenue to play with.

Code:
 With ActivePresentation.Slides(1)
Set oShpA = .Shapes.AddTextbox(Type:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=200, Height:=50).TextFrame _
.TextRange.Text = "That's part right, but there's more!"
Set oEffect = .TimeLine.InteractiveSequences.Add _
.AddEffect(Shape:=oShpA,
effectId:=msoAnimEffectPathCircle)
End With

I wonder if it can't use this because it is a control not a shape, or if I can do this by having the code create a text shape, give it text and animation, and be happy.

No matter what, the code insists on .entryeffect = 257 .

I wonder if the listbox is part of it. I wonder if I need to figure out another way to do this. The problem that I run into is that the text and behavior of the said text box is dependent on the listbox choice. It is a person answering a question and being told if they are right or to try again.

Thank you for your help thus far. Here is a star. :)

misscrf

It is never too late to become what you could have been ~ George Eliot
 



Is it REALLY necessary to run this part of the code in the click event?

Nothing in this code CHANGES with any list selection.

Try running the code BEFORE the show starts. The the ListBox merely does othe stuff unrelated to the annimation.

Skip,

[glasses] [red][/red]
[tongue]
 
no its not, I guess. I just don't understand how to make the entry effect go on a text box, which comes in based on a person's answer of a list box. How else could I do this? I am happy to make this as simple as possible! lol

misscrf

It is never too late to become what you could have been ~ George Eliot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top