Lequocvan
Thành viên thường trực




Em muốn hỏi có code vba nào từ một PC1 yêu cầu chính xác PC2 chạy âm thanh (vì PC2 có loa, PC1 ko loa)
Em tìm trên GPE năm 2009, A. PhanTuHuong có post code bên dưới thì chạy tại PC2 là ổn (thậm chỉ chạy ở local thì ổn hết) nhưng nếu ngồi ở PC1 mà lệnh cho PC2 chạy âm thanh, phát ra loa thì có được không ah?
Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub ListWavFiles()
Dim N As Long
Dim FSO As Object
Dim FF As Object
Dim F As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FF = FSO.GetFolder(Environ("SystemRoot") & "\Media")
For Each F In FF.Files
N = N + 1
Cells(N, 1) = F.Name
Cells(N, 2) = F.Path
Next F
ActiveSheet.Columns(1).AutoFit
End Sub
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 "e:\1million.wav", False
End Sub
Em tìm trên GPE năm 2009, A. PhanTuHuong có post code bên dưới thì chạy tại PC2 là ổn (thậm chỉ chạy ở local thì ổn hết) nhưng nếu ngồi ở PC1 mà lệnh cho PC2 chạy âm thanh, phát ra loa thì có được không ah?
Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub ListWavFiles()
Dim N As Long
Dim FSO As Object
Dim FF As Object
Dim F As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FF = FSO.GetFolder(Environ("SystemRoot") & "\Media")
For Each F In FF.Files
N = N + 1
Cells(N, 1) = F.Name
Cells(N, 2) = F.Path
Next F
ActiveSheet.Columns(1).AutoFit
End Sub
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 "e:\1million.wav", False
End Sub