Adding a sound bite

CoogansBluff

Board Regular
Joined
Mar 7, 2021
Messages
55
Office Version
  1. 2013
Platform
  1. Windows
I've created a dice game that is played Excel. To roll the dice, I can click a button that triggers a macro that calculates the page (F9) and shows the new dice roll.

I was thinking about adding a sound when the dice is rolled, a simple sound bite of dice that's 2 seconds. So you click the button, you get both a dice sound and dice result.

Would it be difficult to add sound? I have a wav file picked out.

And is it worth it? My speadsheet occasionally gets a little slow as it is because of so many formulas that run the game. But it would be cool to have that addition if not too difficult. I've searched ways to do this, and it appears possible, but the explanations were above my experience level w/ Excel.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
One of the easily foundable ways for those who know how to operate a web search, code to paste to the top of a module :​
VBA Code:
Private Declare PtrSafe Function PlaySound& Lib "winmm.dll" (ByVal fSon$, ByVal hmod&, ByVal fdwSound&)

Sub Demo()
    PlaySound "C:\Windows\Media\notify.wav", 0, 3
End Sub
 
Upvote 0
See if this helps :


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", 1)
    'The number 1 allows sound to play while form loads. The number 0 plays sound first, then loads form.
    UserForm1.Show
End Sub
 
Upvote 0
See if this helps :


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", 1)
    'The number 1 allows sound to play while form loads. The number 0 plays sound first, then loads form.
    UserForm1.Show
End Sub

Thank you. But I must admit that I'm pretty ignorant when it comes to VBA stuff.

What steps do I take to get to the place where I'd paste that?
 
Upvote 0
How to create a macro : How To Create a Macro From Scratch in Excel - Excel Macro Mastery


Your WAV file name goes here : Call sndPlaySound32("C:\Users\My\Desktop\Ring03.wav", 1)

Be certain the edit the above path to match your system (the MY colored in blue). Also, be certain your workbook is placed on your desktop or edit the path
to reflect the location where you place the workbook.

Delete this part from macro : UserForm1.Show .... insert a call to the macro that "rolls the dice". For example, if the macro name is Sub RolldDice () ... replace
UserForm1.Show with RolldDice.
 
Upvote 0
Solution
How to create a macro : How To Create a Macro From Scratch in Excel - Excel Macro Mastery


Your WAV file name goes here : Call sndPlaySound32("C:\Users\My\Desktop\Ring03.wav", 1)

Be certain the edit the above path to match your system (the MY colored in blue). Also, be certain your workbook is placed on your desktop or edit the path
to reflect the location where you place the workbook.

Delete this part from macro : UserForm1.Show .... insert a call to the macro that "rolls the dice". For example, if the macro name is Sub RolldDice () ... replace
UserForm1.Show with RolldDice.

Very helpful, making progress. However, I'm getting ''The code in this project must be updated for use on 64-bit system. ...

I've got Excel 2013.
 
Upvote 0
Very helpful, making progress. However, I'm getting ''The code in this project must be updated for use on 64-bit system. ...

I've got Excel 2013.
OK, I think I've figured out the 64-bit issue. ...

Now working to combine the sound bite with the original macro that rolled the dice. Stay tuned.
 
Upvote 0
I'm in business, got the sound to work with the roll dice function.

Thanks to Logit and Marc L!
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,669
Members
448,977
Latest member
moonlight6

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