1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| Declare Function OemToChar& Lib "user32" Alias "OemToCharA" (ByVal lpszSrc _As String, ByVal lpszDst As String)
Public Function OEM_To_ANSI(ByVal sText As String) As String
Dim lResult As Long
Dim sANSI As String
sANSI = Space$(Len(sText))
lResult = OemToChar(sText, sANSI)
OEM_To_ANSI = sANSI
End Function
Sub TestVBA_PowerShellFile()
Dim sPSCmd, sParams As String
Dim sTo, sSubject, sBody, sFrom, sSmtpServer, Reponse As String
sFrom = "moi@free.fr"
sTo = "toi@free.fr"
sSubject = """test VBA PowerShell"""
sBody = """ceci est un test VBA PowerShell"""
sSmtpServer = "smtp.free.fr"
sParams = sFrom & " " & sTo & " " & sSubject & " " & sBody & " " & _
sSmtpServer
sPSCmd = "powershell -ExecutionPolicy Unrestricted " & _
"-File D:\Temp\envoiCourriel.Ps1 " & sParams
'Exécute et capture les messages d'erreur si il y en a
Erreur = CreateObject("WScript.Shell").Exec(sPSCmd).StdErr.ReadAll
If Erreur <> "" Then MsgBox OEM_To_ANSI(Erreur)
End Sub |
Partager