Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 02-23-2015, 12:04 AM
excelledsoftware excelledsoftware is offline Can PowerPoint play a random sound file from a specified directory on slides I designate? Windows 7 64bit Can PowerPoint play a random sound file from a specified directory on slides I designate? Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Sounds great. Here is one more that actually uses a collection. I think the previous codes would have never picked song 1 this could be fixed by adding a "|" to beginning of the soundstring but here is a very simple version of the code that will work right away.
Code:
Sub SetRandomSoundToSlides()
  'Adds a random song into a presentation using the last slide as a data slide
  Dim x As Integer, pst As Presentation, TrackNum As Integer
  Dim SlideArray As Variant, StrNum As Integer, FileName As String
  Dim Directory As String, SoundString As String, SoundCol As Collection
  Set pst = ActivePresentation
  Set SoundCol = New Collection
  
  'Set up the data here
  
  SlideArray = Array(1, 2, 3, 4, 5, 6, 7, 8, 9) 'add in the slides that need a sound file
  Directory = "C:\Users\Admin\Desktop\" 'Location of the sound files
  

  'add all file names to string
  For x = 1 To 100
    StrNum = x
    Select Case StrNum
      Case 0 To 9: FileName = "HYPE00" & x & ".wav"
      Case 10 To 99: FileName = "HYPE0" & x & ".wav"
      Case 100: FileName = "HYPE" & x & ".wav"
    End Select
    SoundCol.Add (FileName)
    FileName = ""
  Next x

  For x = 0 To UBound(SlideArray)
    TrackNum = Int(Rnd() * SoundCol.Count)
    pst.Slides(SlideArray(x)).SlideShowTransition.SoundEffect.ImportFromFile (Directory & SoundCol.Item(TrackNum))
    'remove the song file from future slides
    SoundCol.Remove (TrackNum)
  Next x
  pst.SlideShowWindow.View.GotoSlide (2)
End Sub
Reply With Quote
 

Tags
random, sound

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can PowerPoint play a random sound file from a specified directory on slides I designate? embedded audio file won't play on in powerpoint 2011 on Mac jerryny PowerPoint 3 02-10-2017 09:25 AM
How to make a trimmed audio file play across slides pjb2247 PowerPoint 2 12-06-2014 08:17 AM
I get random "boing" sound on advancing slides. talosian PowerPoint 2 04-22-2014 06:14 AM
Can PowerPoint play a random sound file from a specified directory on slides I designate? avi file wont play in Powerpoint 2010? :( maidmarion30 PowerPoint 1 10-26-2010 10:53 AM
truncating path or renaming audio file to play in powerpoint rbookend PowerPoint 0 05-02-2006 03:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft