Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Creating Sound

  Asked By: Darla    Date: Nov 29    Category: MS Office    Views: 535
  


Can anyone tell me if it is possible to write a macro to make a sound?

Basically I'm trying to create a metronome.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Joann Gardner     Answered On: Nov 29

If you are not particular about the sound, then Beep might do it for
you.

Sub MakeSound()
Beep
End Sub

 
Answer #2    Answered By: Madeeha Malik     Answered On: Nov 29

Not all systems support sound. Determine whether your system supports
sound or not with:

If Not Application.CanPlaySOunds then
MsgBox "Sorry, no sound  on this sytem"
Exit Sub
End if

If you don't get the message above you can continue:

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

Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim SoundFile As Variant


The following command will play the .wav file, let's say it's called
tic.wav:

Call PlaySound("C:\tic.wav", 0&, SND_ASYNC Or SND_FILENAME)


The .wav file is played asynchronously which means that code execution
continues while the sound is playing.

End of plagiarism.

 
Didn't find what you were looking for? Find more on Creating Sound Or get search suggestion and latest updates.




Tagged: