Podsumowując, masz dwa rozwiązania:
Albo umieścisz WaitUntilDone przed EndSub
Albo uruchomisz swoją funkcję w innym wątku
@Konti w innym wątku, to również nie działa, ponieważ przerywa tekst, gdy tylko zakończy się wywoływana funkcja lub sub.
A jeśli uruchomisz działanie nieasynchroniczne, czeka na kontynuację końca funkcji lub sub.
W końcu znalazłem
Function Msg_sonore(sText As String) As Boolean
'Permet de lire le message de manière asynchrone en passant par .vbs
Dim swApp As Object
Dim fso, Dossier, Fichier, f
Dim oWsh As Variant
Set swApp = Application.SldWorks
Set oWsh = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Dossier = Left(swApp.GetCurrentMacroPathName, InStrRev(swApp.GetCurrentMacroPathName, "\"))
Fichier = "PART_MEP_suppr contraintes.vbs"
If Dir(Dossier & Fichier) <> "" Then fso.DeleteFile Dossier & Fichier
Set f = fso.CreateTextFile(Dossier & Fichier, True)
f.WriteLine "'Fichier temporaire, pour lecture message sonore asynchrone"
f.WriteLine "Dim speech"
f.WriteLine "Set speech = CreateObject(""SAPI.SpVoice"")"
f.WriteLine "speech.Speak """ & sText & """"
f.Close
oWsh.ShellExecute Dossier & Fichier
Set oWsh = Nothing
End Function
1 polubienie