View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default play sound when opening workbook

Hi Jim,

The reason is because I adapted a piece of code in my library. In there, it
is being used as a worksheet function, hence a function.

I also tend to write more of my procedures as functions than most, just a
style thing I guess. I read something once by Paul Lomax where he advocated
only ever using functions, which I agree with in concept, even if not in
practice, so as to test for success.

Regards

Bob

"Jim Thomlinson" wrote in message
...
Any reason you implement PlayWavFile as a function returning and empty

string
instead of as a sub? Just curious... Nice code... makes me wish I had

sound
here at work...

"Bob Phillips" wrote:

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


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

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


'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code



--

HTH

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


"Alen32" wrote in message
lkaboutsoftware.com...
I want when I open my workbook to automatically start sound. I have

one
waw file in C:\musik\test.waw.
How can i do that?