vba to assign animation to a picture transferred into powerpoint

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
683
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I have the following vba that copy>pastes a worksheet range from excel into ppt as a picture. What code will then assign a Fade In animation to the picture?
Hope you can help, many thanks.
Code:
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation


Sheet72.Range("G15:S37").CopyPicture Appearance:=xlScreen, Format:=xlPicture
PPPres.Slides(1).Shapes.Paste


With PPPres.Slides(1)
    With .Shapes(.Shapes.Count)
        .LockAspectRatio = msoTrue
        .ScaleHeight 0.8, msoTrue
        .Left = 27
        .Top = 121
    End With
End With
 
Last edited by a moderator:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Something like this I think:
Code:
    Dim shp                   As PowerPoint.Shape
    Dim sld                   As PowerPoint.Slide
    Dim eff                   As PowerPoint.Effect

    Set PPApp = GetObject(, "Powerpoint.Application")
    Set PPPres = PPApp.ActivePresentation


    ActiveSheet.Range("G15:S37").CopyPicture Appearance:=xlScreen, Format:=xlPicture
    Set sld = PPPres.Slides(1)
    Set shp = sld.Shapes.Paste.Item(1)

    'add fade effect to shape
    Set eff = sld.TimeLine.MainSequence.AddEffect _
              (Shape:=shp, effectid:=msoAnimEffectFade, trigger:=msoAnimTriggerOnPageClick)
    ' medium speed (2 secs)
     eff.Timing.Duration = 2
     
    With shp
        .LockAspectRatio = msoTrue
        .ScaleHeight 0.8, msoTrue
        .Left = 27
        .Top = 121
    End With
 
Upvote 0
Hi,
Thanks for your help with this, however ran into a problem - the macro stops at the first line and I get 'Compile error: User-defined type not defined'
Any thoughts?
Rgds
 
Upvote 0
If you're late-binding your code, you'll need to alter what I posted accordingly:
Code:
    Dim shp                   As Object
    Dim sld                   As Object
    Dim eff                   As Object

    Const msoAnimEffectFade As Long = 10
    Const msoAnimTriggerOnPageClick As Long = 1
    
    Set PPApp = GetObject(, "Powerpoint.Application")
    Set PPPres = PPApp.ActivePresentation


    ActiveSheet.Range("G15:S37").CopyPicture Appearance:=xlScreen, Format:=xlPicture
    Set sld = PPPres.Slides(1)
    Set shp = sld.Shapes.Paste.Item(1)

    'add fade effect to shape
    Set eff = sld.TimeLine.MainSequence.AddEffect _
              (Shape:=shp, effectid:=msoAnimEffectFade, trigger:=msoAnimTriggerOnPageClick)
    ' medium speed (2 secs)
     eff.Timing.Duration = 2
     
    With shp
        .LockAspectRatio = msoTrue
        .ScaleHeight 0.8, msoTrue
        .Left = 27
        .Top = 121
    End With
 
Upvote 0
Hi, That works great thanks very much.
Just one final quick question though if I may - what's the code to have the fade in 'after previous' as opposed to 'on click'?
Thanks
 
Upvote 0
Add:
Code:
Const msoAnimTriggerAfterPrevious As Long = 3
and then use that constant instead of msoAnimTriggerOnPageClick
 
Upvote 0
Excellent!
Thanks you have been most helpful :)
 
Upvote 0
Hi,
Have just come across another requirement if possible - is there some code that will put the pasted shape to the back on the ppt slide, ie. code to execute 'Send to Back'?
Rgds
 
Upvote 0
ok, have sussed it... just add .ZOrder msoSendToBack after the sizing of the shape.
 
Upvote 0

Forum statistics

Threads
1,221,566
Messages
6,160,525
Members
451,655
Latest member
rugubara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top