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
 



did you check out the AnimationSettings Property?

Skip,

[glasses] [red][/red]
[tongue]
 
Could you please elaborate? Is there an event that this would go with? I am doing my best at VBA, but I am not an expert like yourself.

Thank you,

misscrf

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



Did you check the AnimationSettings Property in VB Help? If so, what did you find when you applied this property to your coding?

Skip,

[glasses] [red][/red]
[tongue]
 
I used the following:
With Me.txtExample.AnimationSettings
.EntryEffect = ppEffectFlyFromLeft
End With

and it says:
Runtime error 438: Object does not support this method or variable.

:-(


misscrf

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


I assume that txtExample is a Shape Object and Me is a Slide Object?

How did you SET these two objects?

Skip,

[glasses] [red][/red]
[tongue]
 
no, that is how I do coding in Access, I was hoping it would be the same, me is used instead of fully qualifying the object. txtExample is a textbox from the control toolbox.

Is there another way to do this statement?

misscrf

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



Do you understand the Power Point Object Model?

Me in a FORM is the Form Object. You have to understand the Object Model in order to reference objects properly.

Help example indicates...
Code:
Set sObjs = ActivePresentation.Slides.Add(2, ppLayoutText).Shapes
sObjs.Title.TextFrame.TextRange.Text = "Top Three Reasons"
With sObjs.Placeholders(2)
    .TextFrame.TextRange.Text = _
        "Reason 1" & VBNewLine & "Reason 2" & VBNewLine & "Reason 3"
    With .AnimationSettings
        .TextLevelEffect = ppAnimateByFirstLevel
        .EntryEffect = ppEffectFlyFromLeft
        .AfterEffect = ppAfterEffectDim
        .DimColor.RGB = RGB(100, 120, 100)
        .AnimateTextInReverse = True
    End With
End With
You're going to have to figure out how your shapes can adapt.

Skip,

[glasses] [red][/red]
[tongue]
 
I don't understand any of this. I understand if you don't want to explain it further, but can someone please help? I just want to understand how I make txtExample do an animation, and I don't understand how to convert the code in this example into what I specifically need.

Thank you for your help. It is most appreciated.

misscrf

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


Listen! This will take some effort on your part. Don't just whine and beg for an answer. YOU are going to have to dig and try and fail and try again and ask questions and try some more. That's how it OFTEN works. I know, because I've been there MANY TIMES!

Dig into help. Test some things out. USe the Object Browser. Step thru your code and use the Watch Window. How to use the Watch Window as a Power Programming Tool faq707-4594.

If you do some work on your end, there will be experts here to provide help and tips.

Skip,

[glasses] [red][/red]
[tongue]
 
OK, you listen to me. Just because you know more about this, does not give you the excuse to be rude to me. I am not trying to get an easy answer or get out of learning. I have learned all that I know by digging.

What you accuse me of (which I am not doing) is just as bad as what you are doing. Posing to have an answer, but not willing to actually explain it is rude and snobish. I get that you are smart, but don't come here acting like you are so great because you answered my question with a clue. It is not your job to send me on a scavenger hunt.

If you don't want to answer the question, then don't, but don't whine about this is volunteer, because I contribute back to others too. If you are going to answer a question, please have the decency to explain the answer to the person asking the question in terms they understand.

Please have patience for those of us that are not so intelligent and far along as you may be.

misscrf

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



Believe me I have plenty of patience. I was responding to...

"I don't understand any of this. ... I just want to understand how I make txtExample do an animation, and I don't understand how to convert the code in this example into what I specifically need."

It just sounded to me like, "don't confuse me with the facts, just give me an answer!"

I am willing to help, and I will. But you are going to have to try some stuff on your end and report the results. There are not very many experts in PowerPoint. I certainly am NOT one of the few. I DO have some experience understanding objects and therefore can muddle thru an object model that is not as familiar as, for instance, Excel is.

If you want me to butt out, I will. If you want me to try to help, I will.

Skip,

[glasses] [red][/red]
[tongue]
 
I do want your help, and I do appreciate it. Thank you for your patience.

If I might just break down your code, there are some things that I just don't get. I saw this in help too, but shyed away from it, because it added a slide, and objects. I already have them.

Code:
'I am thinking I do not want this, because I have the slides right?
Set sObjs = ActivePresentation.Slides.Add(2, ppLayoutText).Shapes
'Because of my code, the text value is already set, based on a user's choice of a listbox, so how does this code know what textbox I am calling?
sObjs.Title.TextFrame.TextRange.Text = "Top Three Reasons"
With sObjs.Placeholders(2)
    .TextFrame.TextRange.Text = _
        "Reason 1" & VBNewLine & "Reason 2" & VBNewLine & "Reason 3"
    With .AnimationSettings
        .TextLevelEffect = ppAnimateByFirstLevel
        .EntryEffect = ppEffectFlyFromLeft
        .AfterEffect = ppAfterEffectDim
        .DimColor.RGB = RGB(100, 120, 100)
        .AnimateTextInReverse = True
    End With
End With

I will play around with this, and see if I can put this into my code, but I am just not getting how where in this it is calling to my all ready made text box. This is the place I get stuck on any code. I can't understand the code if I can't break it down like a sentence. I need to see Object A do Event X. (if then /case select/with etc)

Thank you,

misscrf

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



First, find out what objects you have. Use a tool like
Code:
sub WhatObjects()
  dim oSld as slide, oShp as shape
  for each osld in activepresentation.slides
    for each oshp in osld.shapes
      with oshp
        msgbox .name
      end with
    next
  next
end sub
you might want to add the Top, Left, Width and Height properties to know where they are located on the slide.

You could rename the textbox shapes in order to be able to just reference them, like txt1, txt2.

The usiing those objects, apply the animation steeting that you want.

Skip,

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



I got this to work...
Code:
Sub ATest()
    Dim oShp As Shape
    For Each oShp In ActivePresentation.Slides(1).Shapes
      With oShp
        If UCase(Left(.Name, 4)) = "TEXT" Then
            With oShp.AnimationSettings
                .TextLevelEffect = ppAnimateByFirstLevel
                .EntryEffect = ppEffectFlyFromLeft
                .AfterEffect = ppAfterEffectDim
                .DimColor.RGB = RGB(100, 120, 100)
                .AnimateTextInReverse = True
            End With
        End If
      End With
    Next
End Sub

Skip,

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


Here's the example with THREE lines of text that get phased in...
Code:
Sub ATest()
    Dim oShp As Shape
    For Each oShp In ActivePresentation.Slides(1).Shapes
      With oShp
        .TextFrame.TextRange.Text = _
        "Reason 1" & vbNewLine & "Reason 2" & vbNewLine & "Reason 3"

        If UCase(Left(.Name, 4)) = "TEXT" Then
            With oShp.AnimationSettings
                .TextLevelEffect = ppAnimateByFirstLevel
                .EntryEffect = ppEffectFlyFromLeft
                .AfterEffect = ppAfterEffectDim
                .DimColor.RGB = RGB(100, 120, 100)
                .AnimateTextInReverse = True
            End With
        End If
      End With
    Next
End Sub

Skip,

[glasses] [red][/red]
[tongue]
 
ok, in the first example, where you have " If UCase(Left(.Name, 4)) = "TEXT" Then"
is the "TEXT" the first four characters in the value of the textbox/object or the name of the object? I am still playing around, but so far, I get no errors and no flying text lol.

Thank you,

misscrf

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


I had simply inserted a textbox using the drawing toolbar.

Then I ran the procedure.

Then I started the SlidShow - hit a [Down Arrow] or [Right Arrow] to bring in each animation.

Skip,

[glasses] [red][/red]
[tongue]
 
ok, when I run the code and look in the window it says that the ucase = "txtExample" so I put that in..

Code:
 For Each oShp In ActivePresentation.Slides(1).Shapes
      With oShp
        If UCase(Left(.Name, 4)) = "txtExample" Then
            With oShp.AnimationSettings
                .EntryEffect = ppEffectFlyFromLeft
                .AnimateTextInReverse = True
            End With
        End If
      End With
    Next

Now I don't get an error, but no effects happen either. I am looking at the procedures you sent and I am doing something wrong with them too. I think I might just go cry now. lol. I am missing something that can't be that hard to do.


misscrf

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


NOTHING appears to happen when you run the procedure.

Did you start your SlideShow?

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top