Playing Midi Files In Excel And Stopping Them

T Clark

New Member
Joined
Dec 7, 2004
Messages
9
I have used the example from "http://www.mrexcel.com/tip007.shtml" that shows how to start a midi/sound file. This works fine. What I want to do is similar to what happens with web pages, in that when the page is left the midi file is stopped (before it would normally finish). While on the page (sheet) if I press "ESC" it will stop, but when I try to use VBA code and the "send keys" command.....

Sub StopIt()
Application.Goto Range("A2")
Range("A1").Select
SendKeys ("{ESC}")
Application.SendKeys ("{ESCape}")
End Sub

.....it will go to the cell selected but ignores the "ESC" command. The sub "StopIt" would be executed when they click on a button to return them to the "home sheet" (menu).

Any help on this out there?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I added the line "DoEvents" after the "sendkeys" command, but the same thing is happening. It reads the command to change cells and does that fine but its like the sendkeys command dont exist. I looked at the code from the link you sent and unless i need to add something else to one of the other code lines, i am doing what you showed there.

Code...
Sub StopIt()
Application.Goto Range("A2")
Range("a1").Select
SendKeys ("{ESC}")
DoEvents
Application.SendKeys ("{ESCape}")
DoEvents
End Sub
 
Upvote 0
I have done a lot of work with media files and found all kinds of problems. What you really need is a Windows Media Player Control - because it does, in fact, give real control. Unfortunately it does not work too well in a worksheet - so you need a userform (which need not be seen). Another problem is that the latest version wmp.dll is not very stable. I have 2 machines running XP. The same workbook works OK in one, 'sometimes' in the other. So use msdxm.ocx instead. This contains install info.
http://www.mrexcel.com/forum/showthread.php?t=289338
Code:
'- SIMPLE ROUTINE TO PLAY & STOP A MEDIA FILE IN EXCEL (etc.) (.MP3, .WAV, .AVI ETC.)
'- WMP controls are very unstable in a Worksheet, so ...
'- make a Userform with only a Windows Media Player control MSDXM.OCX 4/8/2004 (?). No code in the form.
'- This is an older, more stable version. wmp.dll does not always work
'- Can be the basis of a much more complicated form.
'- Brian Baulsom December 2007
'======================================================================================================
'
'======================================================================================================
'- PLAY FILE - the form does not become visible
'======================================================================================================
Sub PlayFile()
    Dim MyMediaFileName As String
    MyMediaFileName = "F:\test.mp3"
    '--------------------------------------------
    With UserForm1
        .MediaPlayer1.Filename = MyMediaFileName
        .MediaPlayer1.Play
        .Hide               ' hide the form
    End With
    '---------------------------------------------
End Sub
'=====================================================================================================
'- STOP PLAYER
'=====================================================================================================
Sub StopPlayer()
    UserForm1.MediaPlayer1.stop
    Unload UserForm1
End Sub
'====================================================================================================
 
Upvote 0
I am sure that this would be a "better" solution, but one of the things i want is for the workbook to be self contained (wav files embedded) so that the music files dont have to be external as is referenced in the solution above. Still hoping there is a solution to this.
 
Upvote 0
Did you manage to find the solution for this problem, I am trying to do the same thing.....have the needed sound file embeded in the worksheet so it doesn't have to pull the file from the C drive as this spreadsheet is shared and not everyone would have the same files.
 
Upvote 0

Forum statistics

Threads
1,216,609
Messages
6,131,723
Members
449,667
Latest member
PSAv

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