sound at wav-file

  • Thread starter Hartmut \(Harry\) Kloppert
  • Start date
H

Hartmut \(Harry\) Kloppert

Some time ago I got an excellent tip here how to do that out of Excel-VBA.
It was recommended:
strWavPath = "C:\path\soundname.wav")
x = Shell("sndrec32.exe /play /close " & Chr(34) & strWavPath &
Chr(34), vbHide)
It worked fine with my XP-computer.

Now I'm on a new Vista machine and it doesn't work anymore ("file not
found").
I found out that sndrec32.exe is no more available in Vista. So, I copied it
from the
old XP-machine into Vista's "System32" folder.

No luck. It still says "file not found". When I open sndrec32.exe manually,
it comes up
but it also tells me that "there was an error updating the registry".

Any idea or any other way to sound a wav-file out of OFFICE XP 2007?
 
K

Karl E. Peterson

Hartmut said:
Some time ago I got an excellent tip here how to do that out of Excel-VBA.
It was recommended:
strWavPath = "C:\path\soundname.wav")
x = Shell("sndrec32.exe /play /close " & Chr(34) & strWavPath &
Chr(34), vbHide)
It worked fine with my XP-computer.

Now I'm on a new Vista machine and it doesn't work anymore ("file not found").
I found out that sndrec32.exe is no more available in Vista. So, I copied it
from the old XP-machine into Vista's "System32" folder.

Ewwwww... Don't do that. Use the API instead...

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

' Sound constants
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_FILENAME = &H20000 ' name is a file name

Public Sub PlaySoundFile(ByVal FileName As String, Optional ByVal Wait As Boolean
= False)
If Wait Then
Call PlaySound(FileName, 0&, SND_FILENAME)
Else
Call PlaySound(FileName, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub

(Above code was indented to highlight wordwrap.)

Later... Karl
 
H

Hartmut \(Harry\) Kloppert

Karl E. Peterson said:
Ewwwww... Don't do that. Use the API instead...

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

' Sound constants
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_FILENAME = &H20000 ' name is a file name

Public Sub PlaySoundFile(ByVal FileName As String, Optional ByVal Wait
As Boolean = False)
If Wait Then
Call PlaySound(FileName, 0&, SND_FILENAME)
Else
Call PlaySound(FileName, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub

(Above code was indented to highlight wordwrap.)

Later... Karl
----
Thanks Karl. I got it to work this way (although I'm not a VBA Programmer,
rather
a C++ guy...). You helped me a lot.

Harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top