Playing Sound.wav

VinceF

Board Regular
Joined
Sep 22, 2007
Messages
220
Office Version
  1. 2016
Platform
  1. Windows
Greetings,

Should this code work?

VBA Code:
Sub ClickSound()

Dim soundFile As String

soundFile = "C:\click.wav"

Call playSound(soundFile, 0)

End Sub


If yes, I'm getting a "Sub or function not Defined" error
If no, please advise as to what's wrong.

Thank You,
VinceF
Win10
Office365
 
It is telling you exactly what the issue is.
You are trying to call a procedure named "playSound", and it cannot find it.
Have you created a procedure called "playSound"?

If not, where did you come up with that?
If from another post, go back and look to make sure you didn't forget to copy over other VBA code or perhaps install an Add-In that contains that.
 
Upvote 0
Include the entire path :

VBA Code:
Option Explicit

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

Sub shwFrm()
    Call sndPlaySound32("C:\Users\My\Desktop\Ring03.wav", 0)
End Sub
 
Upvote 0
Joe and Logit,
Thank you both for your replies.
Unfortunately my VBA skills are limited to pretty much copy/paste

Joe...I created a Module/Sub called ClickSound. I tried replacing "playSound" with "ClickSound" but I still get the error message.
Logit...I copied your code and adjusted the path where the file is and I get the below error message.

Apologize for my limited skills.

When I try to run the below code I'm getting...
Compile error
Invalid inside Procedure
and it highlights "Option Explicit"

VBA Code:
Sub ClickSound()

Option Explicit

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

Sub shwFrm()
    Call sndPlaySound32("C:\clcik.wav", 0)

    
End Sub
 
Upvote 0
VBA Code:
Option Explicit

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

Sub ClickSound()
    Call sndPlaySound32("C:\clcik.wav", 0)   
End Sub
 
Upvote 0
Joe and Logit,
Thank you both for your replies.
Unfortunately my VBA skills are limited to pretty much copy/paste

Joe...I created a Module/Sub called ClickSound. I tried replacing "playSound" with "ClickSound" but I still get the error message.
Logit...I copied your code and adjusted the path where the file is and I get the below error message.

Apologize for my limited skills.

When I try to run the below code I'm getting...
Compile error
Invalid inside Procedure
and it highlights "Option Explicit"

VBA Code:
Sub ClickSound()

Option Explicit

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

Sub shwFrm()
    Call sndPlaySound32("C:\clcik.wav", 0)

 
End Sub
"Option Explicit" needs to be at the very top of the procedure, before any code, like logit shows.

See here: Option Explicit in Excel VBA
 
Upvote 0

Forum statistics

Threads
1,226,795
Messages
6,193,047
Members
453,772
Latest member
aastupin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top