Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default play sound when closing xcel 2007

How do I get Excel to play a sound when I close the program?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default play sound when closing xcel 2007


In the ThisWorkbook module, paste the following code and change the
sound name in Workbook_BeforeClose to either a built-in named Windows
sound or to a wav file.


Private Declare Function sndPlaySound32 _
Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long


Private Sub Workbook_BeforeClose(Cancel As Boolean)
PlayTheSound "Windows Shutdown"
End Sub

Private Sub PlayTheSound(ByVal WhatSound As String)
If Dir(WhatSound, vbNormal) = "" Then
' WhatSound is not a file. Get the file named by
' WhatSound from the Windows\Media directory.
WhatSound = Environ("SystemRoot") & "\Media\" & WhatSound
If InStr(1, WhatSound, ".") = 0 Then
' if WhatSound does not have a .wav extension,
' add one.
WhatSound = WhatSound & ".wav"
End If
If Dir(WhatSound, vbNormal) = vbNullString Then
' Can't find the file. Do a simple Beep.
Beep
Exit Sub
End If
Else
' WhatSound is a file. Use it.
End If
' Finally, play the sound.
sndPlaySound32 WhatSound, 0&
End Sub

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Mon, 28 Dec 2009 12:42:01 -0800, Pirgnori
wrote:

How do I get Excel to play a sound when I close the program?

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
How to insert sound in Excel 2007? MacNOLA Excel Discussion (Misc queries) 7 March 6th 08 12:59 AM
Play sound aac Excel Discussion (Misc queries) 2 December 5th 07 11:24 PM
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
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 10:47 PM.

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"