A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

play sound when closing xcel 2007



 
 
Thread Tools Display Modes
  #1  
Old December 28th, 2009, 08:42 PM posted to microsoft.public.excel.misc
Pirgnori
external usenet poster
 
Posts: 3
Default play sound when closing xcel 2007

How do I get Excel to play a sound when I close the program?
  #2  
Old December 28th, 2009, 09:21 PM posted to microsoft.public.excel.misc
Chip Pearson
external usenet poster
 
Posts: 1,343
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?

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:40 PM.


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