-
Solved: Play .wav sound file when userform opened
Hello
I want to be able to play a .wav sound file when a userform is opened. The following code works ok when you enter your own file path etc. I have entered the code in a module and all works ok manually but I can't get it to work automatically when the userform opens.
[vba]
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_FILENAME As Long = &H20000
Private Sub Knock_Click()
PlaySound "C:\Knock.wav", 0&, SND_FILENAME
'/// where "C:\Knock.wav" gets replaced by your wav's path / name.
End Sub
[/vba]
All suggestions gratefully received.
Gil
-
Try.
[vba]Private Sub UserForm_Activate()
Beep
PlaySound "C:\Knock.wav", 0&, SND_FILENAME
End Sub
[/vba]
-
Hello omnibuster
Your suggestion worked a treat.This is what I added to suit my project.I inserted it in Microsoft Excel Objects/ThisWorkbook
[vba]
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_FILENAME As Long = &H20000
Private Sub Workbook_Open()
PlaySound "C:\Knock.wav", 0&, SND_FILENAME
'/// where "C:\Knock.wav" gets replaced by your wav's path / name.
Application.WindowState = xlMaximized
UserForm1.Show
End Sub
[/vba]
Maybe not the most challenging solution but for a novice like me a great deal of help. If anyone can tell me what the 0&, SND_FILENAME means it may help in my understanding.
Many thanks for all the help
Gil
-
-
Hello GTO
Thank you for the link. Not sure I understand it yet but will be added to my reference library
Gil
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules