Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / August 2008

Tip: Looking for answers? Try searching our database.

PlayWavFile

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
art - 18 Aug 2008 16:55 GMT
Hello:

Does anybody know if there is any issues or problems with function
"PlayWavFile" in 2007? I tried using this but it keeps telling me function
not defined. Please help.
Bernie Deitrick - 18 Aug 2008 18:04 GMT
Art,

Sounds like the declaration was lost:

Declare Function PlayWavFile Lib "winmm.dll" Alias _
   "sndPlaySoundA" (ByVal lpszSoundName As String, _
   ByVal uFlags As Long) As Long

Sub PlayMySound()
   Call PlayWavFile("C:\WINDOWS\MEDIA\Jungle Error.WAV", 0)
End Sub

Signature

HTH,
Bernie
MS Excel MVP

> Hello:
>
> Does anybody know if there is any issues or problems with function
> "PlayWavFile" in 2007? I tried using this but it keeps telling me function
> not defined. Please help.
art - 18 Aug 2008 18:12 GMT
I have this in the worksheet:

Option Explicit
Public Declare Function sndPlaySound Lib "winmm.dll" _
              Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
              ByVal uFlags As Long) As Long

Sub PlayWavFile(WavFileName As String)
       sndPlaySound WavFileName, 1
End Sub

and in the sheet module I have

Sub TestPlayWavFile()
   PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
End Sub

Am I missing something? Please let me know.

> Art,
>
[quoted text clipped - 13 lines]
> > "PlayWavFile" in 2007? I tried using this but it keeps telling me function
> > not defined. Please help.
Bernie Deitrick - 18 Aug 2008 18:23 GMT
Art,

Put it all into a regular codemodule, not in the sheet's codemodule..

HTH,
Bernie
MS Excel MVP

>I have this in the worksheet:
>
[quoted text clipped - 32 lines]
>> > "PlayWavFile" in 2007? I tried using this but it keeps telling me function
>> > not defined. Please help.
art - 18 Aug 2008 18:33 GMT
Can you please give me the whole code in one length since I'm not so famiar
with it. I tried but there is something wrong I'm doing. So please give me
the whole code I should use.

Thanks.

> Art,
>
[quoted text clipped - 40 lines]
> >> > "PlayWavFile" in 2007? I tried using this but it keeps telling me function
> >> > not defined. Please help.
Bernie Deitrick - 18 Aug 2008 19:29 GMT
In a regular codemodule:

Option Explicit
Public Declare Function sndPlaySound Lib "winmm.dll" _
              Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
              ByVal uFlags As Long) As Long

Sub PlayWavFile(WavFileName As String)
       sndPlaySound WavFileName, 1
End Sub

'This is the sub to run:
Sub TestPlayWavFile()
   PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
End Sub

HTH,
Bernie
MS Excel MVP

> Can you please give me the whole code in one length since I'm not so famiar
> with it. I tried but there is something wrong I'm doing. So please give me
[quoted text clipped - 46 lines]
>> >> > "PlayWavFile" in 2007? I tried using this but it keeps telling me function
>> >> > not defined. Please help.
art - 18 Aug 2008 19:46 GMT
Do I copy and paste the whole code in vba?

I got the error message "Compile Error, Constant, fixed length strings,
arrays, user defined types and delare ststaments not allowed as public
members of object moduls".

Please help me.

> In a regular codemodule:
>
[quoted text clipped - 66 lines]
> >> >> > "PlayWavFile" in 2007? I tried using this but it keeps telling me function
> >> >> > not defined. Please help.
Bernie Deitrick - 18 Aug 2008 19:59 GMT
Yes, copy all that code - but you are putting the code into the codemodule of either a sheet object
or the thisworkbook object, not a regular codemodule.

In the VBE, use Insert  / Module  and paste the code into that module.

HTH,
Bernie
MS Excel MVP

> Do I copy and paste the whole code in vba?
>
[quoted text clipped - 74 lines]
>> >> >> > "PlayWavFile" in 2007? I tried using this but it keeps telling me function
>> >> >> > not defined. Please help.
art - 18 Aug 2008 20:06 GMT
Thanks your'e the best.

> Yes, copy all that code - but you are putting the code into the codemodule of either a sheet object
> or the thisworkbook object, not a regular codemodule.
[quoted text clipped - 83 lines]
> >> >> >> > "PlayWavFile" in 2007? I tried using this but it keeps telling me function
> >> >> >> > not defined. Please help.
Rick Rothstein (MVP - VB) - 18 Aug 2008 20:00 GMT
In the VB editor, click Insert/Module on the menu bar and put this part of
Bernie's code in the code window that appears...

Public Declare Function sndPlaySound Lib "winmm.dll" _
              Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
              ByVal uFlags As Long) As Long

Sub PlayWavFile(WavFileName As String)
       sndPlaySound WavFileName, 1
End Sub

Now, in the code window for your worksheet (where I think you originally
placed Bernie's code), delete the code you got from Bernie earlier and just
put this part of it in there instead...

Sub TestPlayWavFile()
   PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
End Sub

This last code is actually a substitute for your own macro if you have one.
If you have your own macro, then put the PlayWavFile statement in it and run
that macro; if you do NOT have your own macro, then just run the
TestPlayWavFile macro instead.

Rick

> Do I copy and paste the whole code in vba?
>
[quoted text clipped - 79 lines]
>> >> >> > function
>> >> >> > not defined. Please help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.