Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Lire un fichier wav

2 réponses
Avatar
Pierre-André
Bonjour,

J'aimerais lire un fichier audio wav en cliquant sur un bouton.

Le chemin et le nom du document se trouvent dans une table.

Si quelqu'un pourrais m'aider, cela serait cool, merci d'avance.

Salutations

2 réponses

Avatar
Gilbert
Bonjour,

Essaie avec le code ci-dessous. Il te permet d'ouvrir un fichier d'après son
extension.

Tu appelles la fonction avec
Réponse = OpenFileExtend(LeCheminEtLeNomDuFichier, Normal, OpExecute)

Code à insérer dans un module standard
'--------------------------------------------------
Option Explicit

Private Declare Function ShellExec Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal Hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long

Public Enum TypeOpen
Hide = 0
Normal = 1
Minimized = 2
Maximized = 3
Restore = 9
End Enum

Public Enum OP
OpExecute = 1
OpPrint = 2
End Enum

Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

Function OpenFileExtend(FileName As String, Optional Window As TypeOpen
=Minimized, Optional Operation As OP = OpExecute) As Variant
Dim lRet As Long
Dim varTaskID As Variant
Dim stRet As String

'Dans Excel (et Word?) remplacer hWndAccessApp par Application.Hwnd
lRet = ShellExec(hWndAccessApp, _
IIf(Operation = OpPrint, "print", "open"), FileName, vbNullString,
vbNullString, Window)
If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " &
FileName, 1)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Erreur: Pas assez de mémoire pour exécuter"
Case ERROR_FILE_NOT_FOUND:
stRet = "Erreur : Fichier non trouvé"
Case ERROR_PATH_NOT_FOUND:
stRet = "Erreur : Chemin non trouvé"
Case ERROR_BAD_FORMAT:
stRet = "Erreur : Type de fichier inconnu"
Case Else:
End Select
End If
OpenFileExtend = lRet & IIf(stRet = "", vbNullString, ", " & stRet)
End Function
'--------------------------------------------------

--
Cordialement,

Gilbert


"Pierre-André" a écrit dans le message de
news:49a4548d$
Bonjour,

J'aimerais lire un fichier audio wav en cliquant sur un bouton.

Le chemin et le nom du document se trouvent dans une table.

Si quelqu'un pourrais m'aider, cela serait cool, merci d'avance.

Salutations




Avatar
Joshua
Genial Gilbert, Merçi beaucoup.



"Gilbert" escribió en el mensaje
news:
Bonjour,

Essaie avec le code ci-dessous. Il te permet d'ouvrir un fichier d'après
son
extension.

Tu appelles la fonction avec
Réponse = OpenFileExtend(LeCheminEtLeNomDuFichier, Normal, OpExecute)

Code à insérer dans un module standard
'--------------------------------------------------
Option Explicit

Private Declare Function ShellExec Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal Hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long

Public Enum TypeOpen
Hide = 0
Normal = 1
Minimized = 2
Maximized = 3
Restore = 9
End Enum

Public Enum OP
OpExecute = 1
OpPrint = 2
End Enum

Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

Function OpenFileExtend(FileName As String, Optional Window As TypeOpen
=Minimized, Optional Operation As OP = OpExecute) As Variant
Dim lRet As Long
Dim varTaskID As Variant
Dim stRet As String

'Dans Excel (et Word?) remplacer hWndAccessApp par Application.Hwnd
lRet = ShellExec(hWndAccessApp, _
IIf(Operation = OpPrint, "print", "open"), FileName, vbNullString,
vbNullString, Window)
If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " &
FileName, 1)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Erreur: Pas assez de mémoire pour exécuter"
Case ERROR_FILE_NOT_FOUND:
stRet = "Erreur : Fichier non trouvé"
Case ERROR_PATH_NOT_FOUND:
stRet = "Erreur : Chemin non trouvé"
Case ERROR_BAD_FORMAT:
stRet = "Erreur : Type de fichier inconnu"
Case Else:
End Select
End If
OpenFileExtend = lRet & IIf(stRet = "", vbNullString, ", " & stRet)
End Function
'--------------------------------------------------

--
Cordialement,

Gilbert


"Pierre-André" a écrit dans le message de
news:49a4548d$
Bonjour,

J'aimerais lire un fichier audio wav en cliquant sur un bouton.

Le chemin et le nom du document se trouvent dans une table.

Si quelqu'un pourrais m'aider, cela serait cool, merci d'avance.

Salutations