Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Countdown in Status Bar to Play Sound

Running Excel 97:

Currently using a Countdown (shown in the Excel tips) from 180 to 0 i
th status bar as a timer.

Would like Excel to automatically play a corresponding WAV file onc
the countdown reaches certain intervals. (30, 10, 0)

Each of the three intervals listed would have their own WAV file.

I am just learning VBA and this site has been very helpful thus far
But I am stuck at this point and don't know how to proceed.

Thanks for the help

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Using Countdown in Status Bar to Play Sound

You can use a Windows API function to play a WAV file. E.g.,

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

Sub PlaySound(FileName As String)
sndPlaySound32 FileName, 0
End Sub

Call this procedure with code like

PlaySound "C:\MyWavFile.wav"



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Full Monty " wrote
in message ...
Running Excel 97:

Currently using a Countdown (shown in the Excel tips) from 180

to 0 in
th status bar as a timer.

Would like Excel to automatically play a corresponding WAV file

once
the countdown reaches certain intervals. (30, 10, 0)

Each of the three intervals listed would have their own WAV

file.

I am just learning VBA and this site has been very helpful thus

far.
But I am stuck at this point and don't know how to proceed.

Thanks for the help!


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using Countdown in Status Bar to Play Sound

Monty,

Here's some code to play a WAV file

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

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


Sub PlayWAVFile(Optional Async As Boolean = True)
Dim WavFile As String
WavFile = "chimes.wav"
WavFile = "C:\Windows\Media\" & WavFile
If Async Then
Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
Else
Call PlaySound(WavFile, 0&, SND_SYNC Or SND_FILENAME)
End If
End Sub

If you need to know how to insert it in your code, we will need to see that

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Full Monty " wrote in message
...
Running Excel 97:

Currently using a Countdown (shown in the Excel tips) from 180 to 0 in
th status bar as a timer.

Would like Excel to automatically play a corresponding WAV file once
the countdown reaches certain intervals. (30, 10, 0)

Each of the three intervals listed would have their own WAV file.

I am just learning VBA and this site has been very helpful thus far.
But I am stuck at this point and don't know how to proceed.

Thanks for the help!


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Countdown in Status Bar to Play Sound

Thanks for the response guys! Again since I am fairly new to VBA code,
am having trouble understanding where you want me to insert it.

The Countdown code I am currently using is:
Sub CountDown()
Dim intCounter As Integer
Dim bln As Boolean
bln = Application.DisplayStatusBar
Application.DisplayStatusBar = True
For intCounter = 180 To 1 Step -1
Application.StatusBar = intCounter & " Seconds..."
Application.Wait Now + TimeSerial(0, 0, 1)
Next intCounter
Application.StatusBar = False
Application.DisplayStatusBar = bln
End Sub

Do I insert the code you guys posted somewhere inside this code? In th
same module but separate section? Or in a new module?

I have all three WAV files located in a folder called "My Folder" in C
drive. Pathway is C:\My Folder\Sound 1" and so on.

Again thanks for all the help! I am learning alot

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using Countdown in Status Bar to Play Sound

Here's the full monty (sorry, couldn't avoid it)

Option Explicit

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

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

Sub CountDown()
Dim intCounter As Integer
Dim bln As Boolean
bln = Application.DisplayStatusBar
Application.DisplayStatusBar = True
For intCounter = 180 To 1 Step -1
If intCounter = 30 Or intCounter = 10 Then
PlayWAVFile "C:\Windows\Media\chimes.wav"
End If
Application.StatusBar = intCounter & " Seconds..."
Application.Wait Now + TimeSerial(0, 0, 1)
Next
PlayWAVFile "C:\Windows\Media\tada.wav"
Application.StatusBar = False
Application.DisplayStatusBar = bln
End Sub

Sub PlayWAVFile(Filename As String, Optional Async As Boolean = True)
If Async Then
Call PlaySound(Filename, 0&, SND_ASYNC Or SND_FILENAME)
Else
Call PlaySound(Filename, 0&, SND_SYNC Or SND_FILENAME)
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Full Monty " wrote in message
...
Thanks for the response guys! Again since I am fairly new to VBA code, I
am having trouble understanding where you want me to insert it.

The Countdown code I am currently using is:
Sub CountDown()
Dim intCounter As Integer
Dim bln As Boolean
bln = Application.DisplayStatusBar
Application.DisplayStatusBar = True
For intCounter = 180 To 1 Step -1
Application.StatusBar = intCounter & " Seconds..."
Application.Wait Now + TimeSerial(0, 0, 1)
Next intCounter
Application.StatusBar = False
Application.DisplayStatusBar = bln
End Sub

Do I insert the code you guys posted somewhere inside this code? In the
same module but separate section? Or in a new module?

I have all three WAV files located in a folder called "My Folder" in C:
drive. Pathway is C:\My Folder\Sound 1" and so on.

Again thanks for all the help! I am learning alot!


---
Message posted from http://www.ExcelForum.com/





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Countdown in Status Bar to Play Sound

Bob,
It works great!

And I am still laughing about your Full Monty comment!

Thanks for all your help!!!!!!!!!!!!!!!!!!!!!!!!!!

--
Message posted from http://www.ExcelForum.com

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
play sound when closing xcel 2007 Pirgnori Excel Discussion (Misc queries) 1 December 28th 09 09:21 PM
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 01:18 AM.

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

About Us

"It's about Microsoft Excel"