View Single Post
 
Old 02-23-2015, 12:04 AM
excelledsoftware excelledsoftware is offline Windows 7 64bit Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 453
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