Wie ktoś z was co zrobić, żeby odtworzyć dźwięk w MS Wordzie za pomocą macro? Mam makro, które wykonuje się dość długo i chciałbym być informowany dźwiękiem, gdy zakończy ono działanie.
sWAVFile = “Sound.wav”
PlaySound(sWAVFile);
oc na końcu
Sub test()
'
' test Makro
'
'
sWAVFile = "c:\Windows\Media\tada.wav"
PlaySound(sWAVFile);
End Sub
Syntax error na
Option Explicit
'API Class to take care of playing the file
Public Declare Function sndPlaySound32 Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub test()
'Call Api to play LoadIt.wav which is in the same folder as
'the active document!
Call sndPlaySound32("test.waw", 0)
End Sub
Był prosty sposób, bynajmniej tak mi się wydaje. Ale jakoś nie umiem tego znaleźć ;/
To też mi wysypuje błąd. Sprawdzałeś to, czy kopiujesz skądś?
Ehh, wav ma być Działa sprawdzałem. A ten pierwszy był z pamięci (korzystałem kiedyś z czegoś w ten deseń, ale musiało mi się coś pomieszać)
Problemem nie jest kod tylko 64bitowy system. Spróbuj zmienić początek na:
Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As LongPtr, ByVal dwFlags As LongPtr) As LongPtr
Jak radzi http://www.mrexcel.com/forum/showthread.php?t=484633
Wyskakuje błąd
na
Po call ma być PlaySoundA a nie sndPlaySound32. Oczywiście możesz zmienić w alias PlaySoundA na sndPlaySound32
Option Explicit
Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As LongPtr, ByVal dwFlags As LongPtr) As LongPtr
Sub test()
'Call Api to play LoadIt.wav which is in the same folder as
'the active document!
Call PlaySoundA("c:\Windows\Media\tada.wav", 0)
End Sub
Efekt:
Pomieszało mi się trochę, sry
Option Explicit
Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As LongPtr, ByVal dwFlags As LongPtr) As LongPtr
Sub test()
'Call Api to play LoadIt.wav which is in the same folder as
'the active document!
Call PlaySound("c:\Windows\Media\tada.wav", 0, 0)
End Sub
Działa, sprawdzałem
Ehh.
Działa, ale teraz mi się moje makro sypie.
Sub test()
For i = 1 To 20
zadanie pętli
Next i
Call PlaySound(“c:\Windows\Media\tada.wav”, 0, 0)
End Sub
Wyskakuje mi, że i nie jest zadeklarowane. ;/ Później nad tym siądę. Piątek wieczór, więc wypada spotkać się z przyjaciółmi.
Option Explicit
Dim i
Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As LongPtr, ByVal dwFlags As LongPtr) As LongPtr
Sub test()
For i = 1 To 3
MsgBox ("costam")
Next i
Call PlaySound("c:\Windows\Media\tada.wav", 0, 0)
End Sub