#1   Report Post  
Posted to microsoft.public.excel.misc
aac aac is offline
external usenet poster
 
Posts: 10
Default Play sound

How do I play a sound when I press a commandbutton.
The sound file is on my desktop.
--
aac
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Play sound

Something like this should do it... Add a command button from the Control
toolbox and pste this code in the sheet (right click the sheet tab and select
view code)...

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, hModule As Long, ByVal dwFlags As Long) As Long

Public Function PlayWavFile(WavFile As String) As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
PlaySound WavFile, 0, SND_ASYNC Or SND_FILENAME
PlayWavFile = ""
End Function

Private Sub CommandButton1_Click()
PlayWavFile "C:\Windows\Media\Microsoft Office 2000\Chimes.wav"
End Sub

--
HTH...

Jim Thomlinson


"aac" wrote:

How do I play a sound when I press a commandbutton.
The sound file is on my desktop.
--
aac

  #3   Report Post  
Posted to microsoft.public.excel.misc
aac aac is offline
external usenet poster
 
Posts: 10
Default Play sound

Thanks Jim,
It works great
--
aac


"Jim Thomlinson" wrote:

Something like this should do it... Add a command button from the Control
toolbox and pste this code in the sheet (right click the sheet tab and select
view code)...

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, hModule As Long, ByVal dwFlags As Long) As Long

Public Function PlayWavFile(WavFile As String) As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
PlaySound WavFile, 0, SND_ASYNC Or SND_FILENAME
PlayWavFile = ""
End Function

Private Sub CommandButton1_Click()
PlayWavFile "C:\Windows\Media\Microsoft Office 2000\Chimes.wav"
End Sub

--
HTH...

Jim Thomlinson


"aac" wrote:

How do I play a sound when I press a commandbutton.
The sound file is on my desktop.
--
aac

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
animated gif won't play Rampdog Excel Discussion (Misc queries) 0 October 29th 07 03:30 AM
Play Sound File Once when cell value condition id met John 1 Excel Discussion (Misc queries) 4 September 1st 07 04:32 PM
play sound when pressing commandbutton Hoyos Excel Discussion (Misc queries) 1 August 19th 07 04:12 PM
Go to and play instereo911 via OfficeKB.com Excel Discussion (Misc queries) 2 October 18th 06 08:25 PM
Can you auto-trigger a sound file to play when a worksheet opens? Nanotexan Excel Worksheet Functions 1 February 5th 06 05:16 PM


All times are GMT +1. The time now is 04:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"