PC Review


Reply
Thread Tools Rate Thread

Adding sount to a macro

 
 
art
Guest
Posts: n/a
 
      14th Aug 2008
Hello:

Can somebody explain to me how to add a sound file to a macro. I need exact
instructions, since what I got (below) does not seem to work for some reason,
and error comes up. Can you please explain how to do it exactly?


Here is what I have:

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


Sub PlayWavFile(WavFileName As String, Wait As Boolean)
If Dir(WavFileName) = "" Then Exit Sub ' no file to play
If Wait Then ' play sound before running any more code
sndPlaySound WavFileName, 0
Else ' play sound while code is running
sndPlaySound WavFileName, 1
End If
End Sub


Sub TestPlayWavFile()
PlayWavFile "c:\foldername\soundfilename.wav", False
MsgBox "This is visible while the sound is playing..."
PlayWavFile "c:\foldername\soundfilename.wav", True
MsgBox "This is visible after the sound is finished playing..."
End Sub


 
Reply With Quote
 
 
 
 
Office_Novice
Guest
Posts: n/a
 
      14th Aug 2008
Hi Art, I Have modified this a bit give it a try


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, Wait As Boolean)
If Dir(WavFileName) = "" Then Exit Sub ' no file to play
If Wait Then ' play sound before running any more code
sndPlaySound WavFileName, 0
Else ' play sound while code is running
sndPlaySound WavFileName, 1
End If
End Sub


Sub TestPlayWavFile()
PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav", False
Debug.Print "This is visible while the sound is playing..."
PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav", True
Debug.Print "This is visible after the sound is finished playing..."
End Sub


"art" wrote:

> Hello:
>
> Can somebody explain to me how to add a sound file to a macro. I need exact
> instructions, since what I got (below) does not seem to work for some reason,
> and error comes up. Can you please explain how to do it exactly?
>
>
> Here is what I have:
>
> Public Declare Function sndPlaySound Lib "winmm.dll" _
> Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> ByVal uFlags As Long) As Long
>
>
> Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> If Wait Then ' play sound before running any more code
> sndPlaySound WavFileName, 0
> Else ' play sound while code is running
> sndPlaySound WavFileName, 1
> End If
> End Sub
>
>
> Sub TestPlayWavFile()
> PlayWavFile "c:\foldername\soundfilename.wav", False
> MsgBox "This is visible while the sound is playing..."
> PlayWavFile "c:\foldername\soundfilename.wav", True
> MsgBox "This is visible after the sound is finished playing..."
> End Sub
>
>

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      14th Aug 2008
Siplified and commented good luck

Option Explicit
Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
'EveryThing From Here Up Should be the First two lines of code

Sub PlayWavFile(WavFileName As String)
'This is its own procedure

sndPlaySound WavFileName, 1
End Sub


Sub TestPlayWavFile()

'Put this line of code in your macro

PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"

End Sub





"art" wrote:

> Hello:
>
> Can somebody explain to me how to add a sound file to a macro. I need exact
> instructions, since what I got (below) does not seem to work for some reason,
> and error comes up. Can you please explain how to do it exactly?
>
>
> Here is what I have:
>
> Public Declare Function sndPlaySound Lib "winmm.dll" _
> Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> ByVal uFlags As Long) As Long
>
>
> Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> If Wait Then ' play sound before running any more code
> sndPlaySound WavFileName, 0
> Else ' play sound while code is running
> sndPlaySound WavFileName, 1
> End If
> End Sub
>
>
> Sub TestPlayWavFile()
> PlayWavFile "c:\foldername\soundfilename.wav", False
> MsgBox "This is visible while the sound is playing..."
> PlayWavFile "c:\foldername\soundfilename.wav", True
> MsgBox "This is visible after the sound is finished playing..."
> End Sub
>
>

 
Reply With Quote
 
art
Guest
Posts: n/a
 
      14th Aug 2008
Looks like I am missing something. How do I start? I add a button from the
form control and add a new macro and copy and paste your vba? Please let me
know because this thing is "bugging" me. Thanks.

"Office_Novice" wrote:

> Siplified and commented good luck
>
> Option Explicit
> Public Declare Function sndPlaySound Lib "winmm.dll" _
> Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> ByVal uFlags As Long) As Long
> 'EveryThing From Here Up Should be the First two lines of code
>
> Sub PlayWavFile(WavFileName As String)
> 'This is its own procedure
>
> sndPlaySound WavFileName, 1
> End Sub
>
>
> Sub TestPlayWavFile()
>
> 'Put this line of code in your macro
>
> PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
>
> End Sub
>
>
>
>
>
> "art" wrote:
>
> > Hello:
> >
> > Can somebody explain to me how to add a sound file to a macro. I need exact
> > instructions, since what I got (below) does not seem to work for some reason,
> > and error comes up. Can you please explain how to do it exactly?
> >
> >
> > Here is what I have:
> >
> > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > ByVal uFlags As Long) As Long
> >
> >
> > Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> > If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> > If Wait Then ' play sound before running any more code
> > sndPlaySound WavFileName, 0
> > Else ' play sound while code is running
> > sndPlaySound WavFileName, 1
> > End If
> > End Sub
> >
> >
> > Sub TestPlayWavFile()
> > PlayWavFile "c:\foldername\soundfilename.wav", False
> > MsgBox "This is visible while the sound is playing..."
> > PlayWavFile "c:\foldername\soundfilename.wav", True
> > MsgBox "This is visible after the sound is finished playing..."
> > End Sub
> >
> >

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      14th Aug 2008

Follow these steps
1) open Excel
2) Tools-->Macro-->Visual Basic Editor
This Is the "VBE"
3)in the VBE go to veiw-->project explorer

On the left hand side of the VBE you should see a file tree looking thing
5) Click VBA Project(yourfilenamehere)

that should reveal Sheet1,2, and 3 and this workbook

6) double click this workbook and Copy and paste this

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

7) Double click the Sheet1 module and paste this
Sub TestPlayWavFile()
PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
End Sub

8) Close the VBE and return to excel

9) Veiw --> Toolbars --> forms
10) Drag the command button to the worksheet
11)Right Click the button -->Assign Macro
12) Select TestPlayWavFile
13) Click OK
14) Close the forms ToolBar

Test out your wav button good luck.

"art" wrote:

> Looks like I am missing something. How do I start? I add a button from the
> form control and add a new macro and copy and paste your vba? Please let me
> know because this thing is "bugging" me. Thanks.
>
> "Office_Novice" wrote:
>
> > Siplified and commented good luck
> >
> > Option Explicit
> > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > ByVal uFlags As Long) As Long
> > 'EveryThing From Here Up Should be the First two lines of code
> >
> > Sub PlayWavFile(WavFileName As String)
> > 'This is its own procedure
> >
> > sndPlaySound WavFileName, 1
> > End Sub
> >
> >
> > Sub TestPlayWavFile()
> >
> > 'Put this line of code in your macro
> >
> > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> >
> > End Sub
> >
> >
> >
> >
> >
> > "art" wrote:
> >
> > > Hello:
> > >
> > > Can somebody explain to me how to add a sound file to a macro. I need exact
> > > instructions, since what I got (below) does not seem to work for some reason,
> > > and error comes up. Can you please explain how to do it exactly?
> > >
> > >
> > > Here is what I have:
> > >
> > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > ByVal uFlags As Long) As Long
> > >
> > >
> > > Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> > > If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> > > If Wait Then ' play sound before running any more code
> > > sndPlaySound WavFileName, 0
> > > Else ' play sound while code is running
> > > sndPlaySound WavFileName, 1
> > > End If
> > > End Sub
> > >
> > >
> > > Sub TestPlayWavFile()
> > > PlayWavFile "c:\foldername\soundfilename.wav", False
> > > MsgBox "This is visible while the sound is playing..."
> > > PlayWavFile "c:\foldername\soundfilename.wav", True
> > > MsgBox "This is visible after the sound is finished playing..."
> > > End Sub
> > >
> > >

 
Reply With Quote
 
art
Guest
Posts: n/a
 
      14th Aug 2008
I followed your instructions exactly and an error message comes up, "compile
Error: Sub or function not defined". What do I do now? please help. Thanks
for your help.

"Office_Novice" wrote:

>
> Follow these steps
> 1) open Excel
> 2) Tools-->Macro-->Visual Basic Editor
> This Is the "VBE"
> 3)in the VBE go to veiw-->project explorer
>
> On the left hand side of the VBE you should see a file tree looking thing
> 5) Click VBA Project(yourfilenamehere)
>
> that should reveal Sheet1,2, and 3 and this workbook
>
> 6) double click this workbook and Copy and paste this
>
> 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
>
> 7) Double click the Sheet1 module and paste this
> Sub TestPlayWavFile()
> PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> End Sub
>
> 8) Close the VBE and return to excel
>
> 9) Veiw --> Toolbars --> forms
> 10) Drag the command button to the worksheet
> 11)Right Click the button -->Assign Macro
> 12) Select TestPlayWavFile
> 13) Click OK
> 14) Close the forms ToolBar
>
> Test out your wav button good luck.
>
> "art" wrote:
>
> > Looks like I am missing something. How do I start? I add a button from the
> > form control and add a new macro and copy and paste your vba? Please let me
> > know because this thing is "bugging" me. Thanks.
> >
> > "Office_Novice" wrote:
> >
> > > Siplified and commented good luck
> > >
> > > Option Explicit
> > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > ByVal uFlags As Long) As Long
> > > 'EveryThing From Here Up Should be the First two lines of code
> > >
> > > Sub PlayWavFile(WavFileName As String)
> > > 'This is its own procedure
> > >
> > > sndPlaySound WavFileName, 1
> > > End Sub
> > >
> > >
> > > Sub TestPlayWavFile()
> > >
> > > 'Put this line of code in your macro
> > >
> > > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> > >
> > > End Sub
> > >
> > >
> > >
> > >
> > >
> > > "art" wrote:
> > >
> > > > Hello:
> > > >
> > > > Can somebody explain to me how to add a sound file to a macro. I need exact
> > > > instructions, since what I got (below) does not seem to work for some reason,
> > > > and error comes up. Can you please explain how to do it exactly?
> > > >
> > > >
> > > > Here is what I have:
> > > >
> > > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > > ByVal uFlags As Long) As Long
> > > >
> > > >
> > > > Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> > > > If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> > > > If Wait Then ' play sound before running any more code
> > > > sndPlaySound WavFileName, 0
> > > > Else ' play sound while code is running
> > > > sndPlaySound WavFileName, 1
> > > > End If
> > > > End Sub
> > > >
> > > >
> > > > Sub TestPlayWavFile()
> > > > PlayWavFile "c:\foldername\soundfilename.wav", False
> > > > MsgBox "This is visible while the sound is playing..."
> > > > PlayWavFile "c:\foldername\soundfilename.wav", True
> > > > MsgBox "This is visible after the sound is finished playing..."
> > > > End Sub
> > > >
> > > >

 
Reply With Quote
 
art
Guest
Posts: n/a
 
      14th Aug 2008
I have Office 2007, if that makes a difference.

"Office_Novice" wrote:

>
> Follow these steps
> 1) open Excel
> 2) Tools-->Macro-->Visual Basic Editor
> This Is the "VBE"
> 3)in the VBE go to veiw-->project explorer
>
> On the left hand side of the VBE you should see a file tree looking thing
> 5) Click VBA Project(yourfilenamehere)
>
> that should reveal Sheet1,2, and 3 and this workbook
>
> 6) double click this workbook and Copy and paste this
>
> 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
>
> 7) Double click the Sheet1 module and paste this
> Sub TestPlayWavFile()
> PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> End Sub
>
> 8) Close the VBE and return to excel
>
> 9) Veiw --> Toolbars --> forms
> 10) Drag the command button to the worksheet
> 11)Right Click the button -->Assign Macro
> 12) Select TestPlayWavFile
> 13) Click OK
> 14) Close the forms ToolBar
>
> Test out your wav button good luck.
>
> "art" wrote:
>
> > Looks like I am missing something. How do I start? I add a button from the
> > form control and add a new macro and copy and paste your vba? Please let me
> > know because this thing is "bugging" me. Thanks.
> >
> > "Office_Novice" wrote:
> >
> > > Siplified and commented good luck
> > >
> > > Option Explicit
> > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > ByVal uFlags As Long) As Long
> > > 'EveryThing From Here Up Should be the First two lines of code
> > >
> > > Sub PlayWavFile(WavFileName As String)
> > > 'This is its own procedure
> > >
> > > sndPlaySound WavFileName, 1
> > > End Sub
> > >
> > >
> > > Sub TestPlayWavFile()
> > >
> > > 'Put this line of code in your macro
> > >
> > > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> > >
> > > End Sub
> > >
> > >
> > >
> > >
> > >
> > > "art" wrote:
> > >
> > > > Hello:
> > > >
> > > > Can somebody explain to me how to add a sound file to a macro. I need exact
> > > > instructions, since what I got (below) does not seem to work for some reason,
> > > > and error comes up. Can you please explain how to do it exactly?
> > > >
> > > >
> > > > Here is what I have:
> > > >
> > > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > > ByVal uFlags As Long) As Long
> > > >
> > > >
> > > > Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> > > > If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> > > > If Wait Then ' play sound before running any more code
> > > > sndPlaySound WavFileName, 0
> > > > Else ' play sound while code is running
> > > > sndPlaySound WavFileName, 1
> > > > End If
> > > > End Sub
> > > >
> > > >
> > > > Sub TestPlayWavFile()
> > > > PlayWavFile "c:\foldername\soundfilename.wav", False
> > > > MsgBox "This is visible while the sound is playing..."
> > > > PlayWavFile "c:\foldername\soundfilename.wav", True
> > > > MsgBox "This is visible after the sound is finished playing..."
> > > > End Sub
> > > >
> > > >

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      15th Aug 2008
I will try the code on 2007 over the weekend and get back with you on monday,
Unfortunately i don’t have ‘07 at the office.
"art" wrote:

> I have Office 2007, if that makes a difference.
>
> "Office_Novice" wrote:
>
> >
> > Follow these steps
> > 1) open Excel
> > 2) Tools-->Macro-->Visual Basic Editor
> > This Is the "VBE"
> > 3)in the VBE go to veiw-->project explorer
> >
> > On the left hand side of the VBE you should see a file tree looking thing
> > 5) Click VBA Project(yourfilenamehere)
> >
> > that should reveal Sheet1,2, and 3 and this workbook
> >
> > 6) double click this workbook and Copy and paste this
> >
> > 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
> >
> > 7) Double click the Sheet1 module and paste this
> > Sub TestPlayWavFile()
> > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> > End Sub
> >
> > 8) Close the VBE and return to excel
> >
> > 9) Veiw --> Toolbars --> forms
> > 10) Drag the command button to the worksheet
> > 11)Right Click the button -->Assign Macro
> > 12) Select TestPlayWavFile
> > 13) Click OK
> > 14) Close the forms ToolBar
> >
> > Test out your wav button good luck.
> >
> > "art" wrote:
> >
> > > Looks like I am missing something. How do I start? I add a button from the
> > > form control and add a new macro and copy and paste your vba? Please let me
> > > know because this thing is "bugging" me. Thanks.
> > >
> > > "Office_Novice" wrote:
> > >
> > > > Siplified and commented good luck
> > > >
> > > > Option Explicit
> > > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > > ByVal uFlags As Long) As Long
> > > > 'EveryThing From Here Up Should be the First two lines of code
> > > >
> > > > Sub PlayWavFile(WavFileName As String)
> > > > 'This is its own procedure
> > > >
> > > > sndPlaySound WavFileName, 1
> > > > End Sub
> > > >
> > > >
> > > > Sub TestPlayWavFile()
> > > >
> > > > 'Put this line of code in your macro
> > > >
> > > > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> > > >
> > > > End Sub
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > "art" wrote:
> > > >
> > > > > Hello:
> > > > >
> > > > > Can somebody explain to me how to add a sound file to a macro. I need exact
> > > > > instructions, since what I got (below) does not seem to work for some reason,
> > > > > and error comes up. Can you please explain how to do it exactly?
> > > > >
> > > > >
> > > > > Here is what I have:
> > > > >
> > > > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > > > ByVal uFlags As Long) As Long
> > > > >
> > > > >
> > > > > Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> > > > > If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> > > > > If Wait Then ' play sound before running any more code
> > > > > sndPlaySound WavFileName, 0
> > > > > Else ' play sound while code is running
> > > > > sndPlaySound WavFileName, 1
> > > > > End If
> > > > > End Sub
> > > > >
> > > > >
> > > > > Sub TestPlayWavFile()
> > > > > PlayWavFile "c:\foldername\soundfilename.wav", False
> > > > > MsgBox "This is visible while the sound is playing..."
> > > > > PlayWavFile "c:\foldername\soundfilename.wav", True
> > > > > MsgBox "This is visible after the sound is finished playing..."
> > > > > End Sub
> > > > >
> > > > >

 
Reply With Quote
 
art
Guest
Posts: n/a
 
      15th Aug 2008
Thank you very much. I really appriciate it.

"Office_Novice" wrote:

> I will try the code on 2007 over the weekend and get back with you on monday,
> Unfortunately i don’t have ‘07 at the office.
> "art" wrote:
>
> > I have Office 2007, if that makes a difference.
> >
> > "Office_Novice" wrote:
> >
> > >
> > > Follow these steps
> > > 1) open Excel
> > > 2) Tools-->Macro-->Visual Basic Editor
> > > This Is the "VBE"
> > > 3)in the VBE go to veiw-->project explorer
> > >
> > > On the left hand side of the VBE you should see a file tree looking thing
> > > 5) Click VBA Project(yourfilenamehere)
> > >
> > > that should reveal Sheet1,2, and 3 and this workbook
> > >
> > > 6) double click this workbook and Copy and paste this
> > >
> > > 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
> > >
> > > 7) Double click the Sheet1 module and paste this
> > > Sub TestPlayWavFile()
> > > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> > > End Sub
> > >
> > > 8) Close the VBE and return to excel
> > >
> > > 9) Veiw --> Toolbars --> forms
> > > 10) Drag the command button to the worksheet
> > > 11)Right Click the button -->Assign Macro
> > > 12) Select TestPlayWavFile
> > > 13) Click OK
> > > 14) Close the forms ToolBar
> > >
> > > Test out your wav button good luck.
> > >
> > > "art" wrote:
> > >
> > > > Looks like I am missing something. How do I start? I add a button from the
> > > > form control and add a new macro and copy and paste your vba? Please let me
> > > > know because this thing is "bugging" me. Thanks.
> > > >
> > > > "Office_Novice" wrote:
> > > >
> > > > > Siplified and commented good luck
> > > > >
> > > > > Option Explicit
> > > > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > > > ByVal uFlags As Long) As Long
> > > > > 'EveryThing From Here Up Should be the First two lines of code
> > > > >
> > > > > Sub PlayWavFile(WavFileName As String)
> > > > > 'This is its own procedure
> > > > >
> > > > > sndPlaySound WavFileName, 1
> > > > > End Sub
> > > > >
> > > > >
> > > > > Sub TestPlayWavFile()
> > > > >
> > > > > 'Put this line of code in your macro
> > > > >
> > > > > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> > > > >
> > > > > End Sub
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > "art" wrote:
> > > > >
> > > > > > Hello:
> > > > > >
> > > > > > Can somebody explain to me how to add a sound file to a macro. I need exact
> > > > > > instructions, since what I got (below) does not seem to work for some reason,
> > > > > > and error comes up. Can you please explain how to do it exactly?
> > > > > >
> > > > > >
> > > > > > Here is what I have:
> > > > > >
> > > > > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > > > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > > > > ByVal uFlags As Long) As Long
> > > > > >
> > > > > >
> > > > > > Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> > > > > > If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> > > > > > If Wait Then ' play sound before running any more code
> > > > > > sndPlaySound WavFileName, 0
> > > > > > Else ' play sound while code is running
> > > > > > sndPlaySound WavFileName, 1
> > > > > > End If
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > > Sub TestPlayWavFile()
> > > > > > PlayWavFile "c:\foldername\soundfilename.wav", False
> > > > > > MsgBox "This is visible while the sound is playing..."
> > > > > > PlayWavFile "c:\foldername\soundfilename.wav", True
> > > > > > MsgBox "This is visible after the sound is finished playing..."
> > > > > > End Sub
> > > > > >
> > > > > >

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      18th Aug 2008
OK, I tried this on xl 2007 and 2003 And had no trouble, Keep trying you'll
figure it out. Let me know if i can be more help.

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


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


"art" wrote:

> Thank you very much. I really appriciate it.
>
> "Office_Novice" wrote:
>
> > I will try the code on 2007 over the weekend and get back with you on monday,
> > Unfortunately i don’t have ‘07 at the office.
> > "art" wrote:
> >
> > > I have Office 2007, if that makes a difference.
> > >
> > > "Office_Novice" wrote:
> > >
> > > >
> > > > Follow these steps
> > > > 1) open Excel
> > > > 2) Tools-->Macro-->Visual Basic Editor
> > > > This Is the "VBE"
> > > > 3)in the VBE go to veiw-->project explorer
> > > >
> > > > On the left hand side of the VBE you should see a file tree looking thing
> > > > 5) Click VBA Project(yourfilenamehere)
> > > >
> > > > that should reveal Sheet1,2, and 3 and this workbook
> > > >
> > > > 6) double click this workbook and Copy and paste this
> > > >
> > > > 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
> > > >
> > > > 7) Double click the Sheet1 module and paste this
> > > > Sub TestPlayWavFile()
> > > > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> > > > End Sub
> > > >
> > > > 8) Close the VBE and return to excel
> > > >
> > > > 9) Veiw --> Toolbars --> forms
> > > > 10) Drag the command button to the worksheet
> > > > 11)Right Click the button -->Assign Macro
> > > > 12) Select TestPlayWavFile
> > > > 13) Click OK
> > > > 14) Close the forms ToolBar
> > > >
> > > > Test out your wav button good luck.
> > > >
> > > > "art" wrote:
> > > >
> > > > > Looks like I am missing something. How do I start? I add a button from the
> > > > > form control and add a new macro and copy and paste your vba? Please let me
> > > > > know because this thing is "bugging" me. Thanks.
> > > > >
> > > > > "Office_Novice" wrote:
> > > > >
> > > > > > Siplified and commented good luck
> > > > > >
> > > > > > Option Explicit
> > > > > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > > > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > > > > ByVal uFlags As Long) As Long
> > > > > > 'EveryThing From Here Up Should be the First two lines of code
> > > > > >
> > > > > > Sub PlayWavFile(WavFileName As String)
> > > > > > 'This is its own procedure
> > > > > >
> > > > > > sndPlaySound WavFileName, 1
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > > Sub TestPlayWavFile()
> > > > > >
> > > > > > 'Put this line of code in your macro
> > > > > >
> > > > > > PlayWavFile "C:\WINDOWS\Media\Windows XP Startup.Wav"
> > > > > >
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > "art" wrote:
> > > > > >
> > > > > > > Hello:
> > > > > > >
> > > > > > > Can somebody explain to me how to add a sound file to a macro. I need exact
> > > > > > > instructions, since what I got (below) does not seem to work for some reason,
> > > > > > > and error comes up. Can you please explain how to do it exactly?
> > > > > > >
> > > > > > >
> > > > > > > Here is what I have:
> > > > > > >
> > > > > > > Public Declare Function sndPlaySound Lib "winmm.dll" _
> > > > > > > Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
> > > > > > > ByVal uFlags As Long) As Long
> > > > > > >
> > > > > > >
> > > > > > > Sub PlayWavFile(WavFileName As String, Wait As Boolean)
> > > > > > > If Dir(WavFileName) = "" Then Exit Sub ' no file to play
> > > > > > > If Wait Then ' play sound before running any more code
> > > > > > > sndPlaySound WavFileName, 0
> > > > > > > Else ' play sound while code is running
> > > > > > > sndPlaySound WavFileName, 1
> > > > > > > End If
> > > > > > > End Sub
> > > > > > >
> > > > > > >
> > > > > > > Sub TestPlayWavFile()
> > > > > > > PlayWavFile "c:\foldername\soundfilename.wav", False
> > > > > > > MsgBox "This is visible while the sound is playing..."
> > > > > > > PlayWavFile "c:\foldername\soundfilename.wav", True
> > > > > > > MsgBox "This is visible after the sound is finished playing..."
> > > > > > > End Sub
> > > > > > >
> > > > > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro adding Mak Microsoft Excel Programming 5 21st Mar 2009 04:53 PM
Adding a Tab in a Macro michaelberrier@gmail.com Microsoft Excel Misc 10 28th Feb 2006 09:57 PM
Adding a row with macro =?Utf-8?B?TmlnZWw=?= Microsoft Excel Programming 3 5th May 2005 11:38 AM
Adding Row to this macro =?Utf-8?B?TmlnZWw=?= Microsoft Excel Misc 2 4th May 2005 05:27 PM
Adding macro code to Personal Macro Workbook mika Microsoft Excel Misc 2 16th Oct 2003 09:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:49 AM.