Re : [VBA] Envoyer un mail avec Outlook sans Object Library
Evidemment on a beau chercher on ne trouve jamais... Sauf 10 minutes après avoir poser la question.
Je partage ma trouvaille.
Si comme moi vous cherchiez un code qui vous permet d'envoyer un email sans OBJECT LIBRARY le voici :
Sub SendOLMail_LateBound()
Dim oAPP As Object
Dim oItem As Object
' need to declare this constant as it has no meaning without
' the reference set to the Outlook library
Const olMailItem As Long = 0
' instantiate the Application - cannot use New without a reference
' so we must use CreateObject
Set oAPP = CreateObject("Outlook.Application")
' #######################################
' NOTE: THE REST OF THE CODE IS IDENTICAL
' #######################################
' create a new email
Set oItem = oAPP.CreateItem(olMailItem)
' set basic properties and display the email
With oItem
.To = "foo@bar.com"
.Subject = "this is a test"
.Body = "nothing to see here"
.Display
End With
End Sub