ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Playing sounds on opening a worksheet or shortcut (https://www.excelbanter.com/excel-programming/327563-playing-sounds-opening-worksheet-shortcut.html)

MusicusMalus

Playing sounds on opening a worksheet or shortcut
 
How do I link a specific wav file to a file so that when it is opened, the
sound plays for that file only.

Don Guillett[_4_]

Playing sounds on opening a worksheet or shortcut
 
try this idea

Option Private Module
Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Sub playit()
SoundName$ = "c:\yourfolder\yourwavefilenam.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub


--
Don Guillett
SalesAid Software

"MusicusMalus" wrote in message
...
How do I link a specific wav file to a file so that when it is opened, the
sound plays for that file only.




Tom Ogilvy

Playing sounds on opening a worksheet or shortcut
 
You might want to include the constant declarations as well:

Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Const SND_SYNC = 0
Const SND_ASYNC = 1
Const SND_NODEFAULT = 2
Const SND_MEMORY = 4
Const SND_LOOP = 8
Const SND_NOSTOP = 16


Sub playit()
SoundName$ = "C:\WINDOWS\MEDIA\Jungle Asterisk.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub

--
Regards,
Tom Ogilvy


"Don Guillett" wrote in message
...
try this idea

Option Private Module
Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Sub playit()
SoundName$ = "c:\yourfolder\yourwavefilenam.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub


--
Don Guillett
SalesAid Software

"MusicusMalus" wrote in message
...
How do I link a specific wav file to a file so that when it is opened,

the
sound plays for that file only.






MusicusMalus

Playing sounds on opening a worksheet or shortcut
 
Thanks for the suggestions, but I've run into a wall.

When I use the "Option Private Module" at the beginning of the code, I get
an= compile error saying, "Option Private Module not permitted in an option
module".

So whe I remove that phrase and run again using your suggested code, I get
another compile error saying, "Constants, fixed-length strings, arrays,
user-deined types and Declare statements not allowed as Public members of
object modules."

This doesn't make sense. I'm running this code as a macro in visual basic.
Anything I'm missing?

Christi

"Tom Ogilvy" wrote:

You might want to include the constant declarations as well:

Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Const SND_SYNC = 0
Const SND_ASYNC = 1
Const SND_NODEFAULT = 2
Const SND_MEMORY = 4
Const SND_LOOP = 8
Const SND_NOSTOP = 16


Sub playit()
SoundName$ = "C:\WINDOWS\MEDIA\Jungle Asterisk.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub

--
Regards,
Tom Ogilvy


"Don Guillett" wrote in message
...
try this idea

Option Private Module
Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Sub playit()
SoundName$ = "c:\yourfolder\yourwavefilenam.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub


--
Don Guillett
SalesAid Software

"MusicusMalus" wrote in message
...
How do I link a specific wav file to a file so that when it is opened,

the
sound plays for that file only.







Chip Pearson

Playing sounds on opening a worksheet or shortcut
 
Change the Declare statement to Private Declare.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"MusicusMalus" wrote in
message
...
Thanks for the suggestions, but I've run into a wall.

When I use the "Option Private Module" at the beginning of the
code, I get
an= compile error saying, "Option Private Module not permitted
in an option
module".

So whe I remove that phrase and run again using your suggested
code, I get
another compile error saying, "Constants, fixed-length strings,
arrays,
user-deined types and Declare statements not allowed as Public
members of
object modules."

This doesn't make sense. I'm running this code as a macro in
visual basic.
Anything I'm missing?

Christi

"Tom Ogilvy" wrote:

You might want to include the constant declarations as well:

Declare Function sndPlaySound Lib "WINMM.DLL" Alias
"sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As
Long
Const SND_SYNC = 0
Const SND_ASYNC = 1
Const SND_NODEFAULT = 2
Const SND_MEMORY = 4
Const SND_LOOP = 8
Const SND_NOSTOP = 16


Sub playit()
SoundName$ = "C:\WINDOWS\MEDIA\Jungle Asterisk.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub

--
Regards,
Tom Ogilvy


"Don Guillett" wrote in message
...
try this idea

Option Private Module
Declare Function sndPlaySound Lib "WINMM.DLL" Alias
"sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long)
As Long

Sub playit()
SoundName$ = "c:\yourfolder\yourwavefilenam.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub


--
Don Guillett
SalesAid Software

"MusicusMalus"
wrote in message
...
How do I link a specific wav file to a file so that when
it is opened,

the
sound plays for that file only.








MusicusMalus

Playing sounds on opening a worksheet or shortcut
 
Thanks everyone. The macro works now when I run it.

However, it doesn't automatically run when the worksheet opens (which is
what I was trying to do). I've checked my security levels to make sure they
don't interfere.

What else am I overlooking?

"Chip Pearson" wrote:

Change the Declare statement to Private Declare.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"MusicusMalus" wrote in
message
...
Thanks for the suggestions, but I've run into a wall.

When I use the "Option Private Module" at the beginning of the
code, I get
an= compile error saying, "Option Private Module not permitted
in an option
module".

So whe I remove that phrase and run again using your suggested
code, I get
another compile error saying, "Constants, fixed-length strings,
arrays,
user-deined types and Declare statements not allowed as Public
members of
object modules."

This doesn't make sense. I'm running this code as a macro in
visual basic.
Anything I'm missing?

Christi

"Tom Ogilvy" wrote:

You might want to include the constant declarations as well:

Declare Function sndPlaySound Lib "WINMM.DLL" Alias
"sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As
Long
Const SND_SYNC = 0
Const SND_ASYNC = 1
Const SND_NODEFAULT = 2
Const SND_MEMORY = 4
Const SND_LOOP = 8
Const SND_NOSTOP = 16


Sub playit()
SoundName$ = "C:\WINDOWS\MEDIA\Jungle Asterisk.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub

--
Regards,
Tom Ogilvy


"Don Guillett" wrote in message
...
try this idea

Option Private Module
Declare Function sndPlaySound Lib "WINMM.DLL" Alias
"sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long)
As Long

Sub playit()
SoundName$ = "c:\yourfolder\yourwavefilenam.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
End Sub


--
Don Guillett
SalesAid Software

"MusicusMalus"
wrote in message
...
How do I link a specific wav file to a file so that when
it is opened,
the
sound plays for that file only.










All times are GMT +1. The time now is 09:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com