Skip to content

Instantly share code, notes, and snippets.

@JimMoyle
Last active May 20, 2024 04:55
Show Gist options
  • Save JimMoyle/4cdf2d7fca960ccecc17f797957ce3f7 to your computer and use it in GitHub Desktop.
Save JimMoyle/4cdf2d7fca960ccecc17f797957ce3f7 to your computer and use it in GitHub Desktop.
Copy randomize and paste animations in Powerpoint
$shapeName = 'Rounded Rectangle 664'
Add-type -AssemblyName office
$Application = New-Object -ComObject powerpoint.application
$application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
$powerpointFile = "D:\PoSHCode\GitLocal\PowerPoint\RandomLogoff3.pptx"
$presentation = $application.Presentations.open($powerpointFile)
$slide = $presentation.Slides[1]
$one = $slide.Shapes | Where-Object { $_.Name -eq $shapeName }
$one.PickupAnimation()
$ids = $slide.shapes | Where-Object { $_.Name -ne $shapeName -and $_.AutoShapeType -eq 5 } | Select-Object -ExpandProperty 'Id'
while ($ids.count -gt 0) {
$randomId = $ids | get-random
$shape = $slide.Shapes | Where-Object { $_.Id -eq $randomId }
$shape.ApplyAnimation()
$ids = $ids | Where-Object { $_ -ne $randomId }
}
$presentation.Save()
$presentation.Close()
$application.quit()
$application = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()
Write-Output 'Done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment