Music file associated with an Excel file.

  • Thread starter Thread starter SteBar
  • Start date Start date
S

SteBar

Is it possible that when I open up a particular Excel file a particular
wav/midi/mp3 music file will automatically start playing? If so, how do I
do it?

Thanks - Steve B.
 
Steve,

Put this code in a normal code module

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, _
hModule As Long, _
ByVal dwFlags As Long) As Long


Public Function PlayWavFile(WavFile As String) As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
PlaySound WavFile, 0, SND_ASYNC Or SND_FILENAME
PlayWavFile = ""
End Function


and then in ThisWorkbook add this code



Private Sub Workbook_Open()

PlayWavFile ("C:\Windows\Media\Microsoft Office 2000\Chimes.wav")End Sub
--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Bob,

Playsound won't play mp3 or mid files. All you'll hear is that "donk"
(which is ding.wav).
 
Hi Earl,

Yes this only does WAV. You need separate code for MP3 and MIDI., and you
halved to stream it through the appropriate device AFAIK, so it is not
appropriate for this sort of use.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
So maybe you could use the windows default application that's associated with
that file extension:

Option Explicit
Private Sub Workbook_Open()
Shell "Start ""C:\My Documents\My Music\my song.mp3"""
End Sub

This starts it, but does give a warning message:
Option Explicit
Private Sub Workbook_Open()
ActiveWorkbook.FollowHyperlink "C:\My Documents\My Music\my song.mp3"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top