Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro to play wave file in current directory

Hello all,
I am using the following code to play a wave file and it works
perfectly.

Sub PlayMe3()
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim retval As Long
retval = PlaySound("C:\ABCDirectory\ACDB\wavtest.wav", _
0, SND_ASYNC Or SND_FILENAME)
End Sub

However, if the directory name is changed it will not work without changing
the name in the macro as well. Can anyone suggest a change in the macro to
play the wave file in the directory what ever the name of the directory is?
The wave file is normally saved in the same directory as the excel file. So
basically the macro needs to call up the wave file in what ever the
directory is that the excel file resides in. I was thinking something like:

Sub PlayMe3()
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim retval As Long
retval = PlaySound("..\..\wavtest.wav", _
0, SND_ASYNC Or SND_FILENAME)
End Sub

....this did not work, by the way. Any help is appreciated.

TIA,
yo beee



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Macro to play wave file in current directory

However, if the directory name is changed it will not work without changing
the name in the macro as well. Can anyone suggest a change in the macro to
play the wave file in the directory what ever the name of the directory is?
The wave file is normally saved in the same directory as the excel file. So
basically the macro needs to call up the wave file in what ever the
directory is that the excel file resides in. I was thinking something like:

Sub PlayMe3()
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim retval As Long
retval = PlaySound("..\..\wavtest.wav", _
0, SND_ASYNC Or SND_FILENAME)
End Sub


try this:

retval = PlaySound(ThisWorkbook.Path & "\wavtest.wav", _
0, SND_ASYNC Or SND_FILENAME)

--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro to play wave file in current directory

Put it in a function as a first step to add flexibility.

Then use ThisWorkbook for the call

PlayWavFile ThisWorkbook/Path & "\wavtest.wav"

if you want to run it in the activeworkbook.directory, use

Play WavFile ActiveWorkbook & "\wavtest.wav"

'-----------------------------------------------------------------
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


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"yo beee" wrote in message
...
Hello all,
I am using the following code to play a wave file and it works
perfectly.

Sub PlayMe3()
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim retval As Long
retval = PlaySound("C:\ABCDirectory\ACDB\wavtest.wav", _
0, SND_ASYNC Or SND_FILENAME)
End Sub

However, if the directory name is changed it will not work without

changing
the name in the macro as well. Can anyone suggest a change in the macro to
play the wave file in the directory what ever the name of the directory

is?
The wave file is normally saved in the same directory as the excel file.

So
basically the macro needs to call up the wave file in what ever the
directory is that the excel file resides in. I was thinking something

like:

Sub PlayMe3()
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim retval As Long
retval = PlaySound("..\..\wavtest.wav", _
0, SND_ASYNC Or SND_FILENAME)
End Sub

...this did not work, by the way. Any help is appreciated.

TIA,
yo beee





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
open file in current directory Tomo Excel Worksheet Functions 1 January 12th 08 12:04 AM
open file in current directory Tomo Excel Discussion (Misc queries) 1 January 11th 08 11:48 PM
How can i play a wave file in excel? pj Excel Discussion (Misc queries) 2 November 25th 05 07:36 PM
Macro to Play Wave File yo beee Excel Programming 3 November 3rd 03 02:56 AM
Macro to play wave file yo beee Excel Programming 1 October 29th 03 11:42 PM


All times are GMT +1. The time now is 07:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"