Wav sound playing on 1 macro, not another

CoogansBluff

Board Regular
Joined
Mar 7, 2021
Messages
55
Office Version
  1. 2013
Platform
  1. Windows
I've created a sports game on Excel. It loads lineups with a macro, and the macro plays a little tune (wave file) at the end when a lineup is loaded.

The wave file plays in some, but not others. Trying to figure out how they are different.

It plays it this one:

Sub AwayAlabama2012()
'
' AwayAlabama2012 Macro
'

'
Sheets("Lineups").Select
Range("D1415:T1427").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Master").Select
Range("B4").Select
ActiveSheet.Paste
Sheets("Lineups").Select
Range("D1429:T1441").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Master").Select
Range("B32").Select
ActiveSheet.Paste
Range("Q4").Select
Application.CutCopyMode = False
Selection.Copy
Range("U2").Select
ActiveSheet.Paste
PlaySound "D:\Smith's Data\Desktop\WCWS\Roll Tide.wav", 0, 3
End Sub


But it does not play in this one. I get Compile error: Sub or Function not defined. It works to load the lineup if I delete the PlaySound line.

The macro above was written in an earlier Excel version while the macro below was written in Excel365, if that matters.


Sub AwayAlabama2021()
'
' AwayAlabama2021 Macro
'

'
Sheets("Lineups").Select
Range("D1415:T1427").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Master").Select
Range("B4").Select
ActiveSheet.Paste
Range("Q4").Select
Application.CutCopyMode = False
Selection.Copy
Range("U2").Select
ActiveSheet.Paste
Sheets("Lineups").Select
Range("D1429:T1441").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Master").Select
ActiveWindow.SmallScroll Down:=3
Range("B32").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Calculate
ActiveWindow.SmallScroll Down:=-24
Range("A5").Select
PlaySound "D:\Smith's Data\Desktop\WCWS\Roll Tide.wav", 0, 3
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I discovered the problem. I need to have this at the top:
(Although I don't recall why; might have something to do w/ 64 and 32 bit).


Private Declare PtrSafe Function PlaySound& Lib "winmm.dll" (ByVal fSon$, ByVal hmod&, ByVal fdwSound&)
 
Upvote 0
Solution
You can also shorten your code by not using .Select
UNTESTED
VBA Code:
Sub AwayAlabama2021()
Sheets("Lineups").Range("D1415:T1427").Copy Sheets("Master").Range("B4")
With Sheets("Master")
.Range("Q4").Copy .Range("U2")
End With
Sheets("Lineups").Range("D1429:T1441").Copy Sheets("Master").Range("B32")
Calculate
Sheets("Master").Range("A5").Select
PlaySound "D:\Smith's Data\Desktop\WCWS\Roll Tide.wav", 0, 3
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,470
Messages
6,124,990
Members
449,201
Latest member
Lunzwe73

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