Once again, I am borrowing from an Excel technique from John Walkenbach, in this case playing a .wav file in Excel.
I have modified his code by coverting it to a function procedure with one argument for running a specified wav file. Copy into a module in the VBE.
Private Declare Function PlaySound Lib “winmm.dll” _
Alias “PlaySoundA” (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Function PlayWAV(fName As String)
PlayWAV = “”
WAVFile = fName & “.wav”
WAVFile = ThisWorkbook.Path & “\” & WAVFile
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
This procedure assumes that the wav files to be played are in the same folder as the workbook.
In order to play a random sound, I made these 2 defined name formulas.
So, the .wav files starting with, in this example, (chicken, horse, kitten, owl and cow) must exist for this function to work. You must personalize this array so that this technique will work with your own wav files.
Now, enter this function in a worksheet cell
Each time that the worksheet is recalculated, a random sound will play. I hope that you will find this useful.