macro to play a.wav file

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
782
Office Version
  1. 365
Platform
  1. Windows
Hello,
Could I use a macro to open/play a .wav file? I have a bunch of "funny" 2 and 3 sec sayings that I would like to use as an event macro. They are in a folder on my hard drive, but not in any program. The path is :c:\wavefile\gooutside.wav. Another thought, could I have the macro randomly play one from a list?

Maybe, I've too much free time on my hands! :biggrin:

Mike
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi, Peter

I tried to adapt the code from the link you gave me, but I can't get it to work. The file path is C:\wavefile\gooutside.wav. I've already learned about "event macros" from using this site :biggrin: If it will make it easier I can move the wave file to the excel folder. I'm using Windows XP and Excel 2007. Also is there code to have a random sound from a list maybe in Personal.xls.

Mike :biggrin:
 
Upvote 0
This worked for me - all of the code goes into the sheet's code module

Code:
Option Explicit

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


Private Sub Worksheet_Change(ByVal Target As Range)
Dim WAVFile As String
If Target.Address(False, False) = "A1" Then
    WAVFile = "C:\Test\doh.wav"
    Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub

You will need to change the path and filename to that of your WAV file.
 
Upvote 0
Hi Peter,

Works like a charm. :biggrin: I had the WaveFile = all messed up. Any way for it to randomly pick from a list?


Mike
 
Upvote 0
Thanks Pete,
I'll work on it over the weekend. I think I can make it work by using that macro to copy it to a cell and use an event macro.........
Any way, thanks for your help. Have a good weekend


Mike (y)
 
Upvote 0
I made a list of my wave files in sheet1, A:1 to A:30. Using the link that VoG gave me (thanks VoG :biggrin:) and changing A:A to A1:A30 and ….*1000 to ...*30, I am able to bring up a random .wav in b:1 of the same sheet. Question: How would I use the code that VoG gave me ( thanks again VoG :biggrin:) to refer to B:1 instead of
HTML:
WAVFile = "C:\Test\doh.wav"
Mike<?xml:namespace prefix = o /><o:p></o:p>
 
Upvote 0
Hey Pete,
Thanks. I was able to modify the code and formula so that when data is entered in a cell, a random .wav is played. I'm going to have some supprised people soon :ROFLMAO:


Thanks again for all your help. Have a couple on me ! (y)

Mike
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,510
Members
448,967
Latest member
screechyboy79

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