Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

including sound wavs in VBA

Status
Not open for further replies.

gonzo67

Technical User
Oct 11, 2003
5
CA
How do I refer to sound wavs in VBA 2002 code? Do I create an object that I refer to? Can I create a function that I can call? What type should it be, Thread, Object, etc? I simply want the sound to start on a button click.
 
How 'bout this...

Code:
Option Explicit

Private Const SND_ASYNC = &H1
Private Const SND_FILENAME = &H20000
Private Const SND_NOWAIT = &H2000
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Sub Button1_Click()
    PlaySound ThisWorkbook.Path & "\ButtonClick.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC Or SND_NOWAIT
End Sub

HtH,

Rob

-Focus on the solution to the problem, not the obstacles in the way.-
 
What about something like this ?
ActiveWorkbook.FollowHyperlink "\path\to\file.wav"

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Here's another using the media player.

Step through the code in the debugger.

Darrell

Code:
Private Sub PlayMedia()
 Dim oMediaPlayer As Object
 Set oMediaPlayer = CreateObject("WMPlayer.OCX")

 oMediaPlayer.settings.volume = 100

 oMediaPlayer.URL = "c:\windows\media\town.mid"

 oMediaPlayer.Close 'to stop playing - Closes the player resources
 Set oMediaPlayer = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top