ForEachLoop,
Il semble que votre question ait trouvé une réponse en grande partie. Je vais simplement ajouter quelques informations par souci de clarté et pour apporter une réponse à cette question. Un utilisateur des Forums Microsoft, Ossiemac, a noté que LateBinding était la solution comme l'a déclaré Siddarth Rout. Comme le sous-entend Siddarth, cela signifie que vous n'avez pas à vous soucier des références.
Ossiemac a fourni un exemple de code pour utiliser le LateBinding dans l'envoi d'un email, que j'ai reformaté et placé ici :
Private Sub btnLateBindMethod_Click()
' Variables used for LateBinding
Dim objOutlook As Object 'Outlook.Application
Dim objEmail As Object 'Outlook.MailItem
Dim objNameSpace As Object 'Outlook.NameSpace
Const OutLookMailItem As Long = 0 'For Late Binding
Const OutLookFolderInbox As Long = 6 'For Late Binding
Const OutLookFormatHTML As Long = 2 'For Late Binding
Dim strSubject As String
Dim strAddress As String
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlook Is Nothing Then
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
objNameSpace.GetDefaultFolder(OutLookFolderInbox).Display
End If
Set objEmail = objOutlook.CreateItem(OutLookMailItem)
strSubject = "Hello World"
With objEmail
'.To = strToAddress 'Commented to prevent accidental send
.Subject = strSubject
.BodyFormat = OutLookFormatHTML
.Display
'Full Name of window can change depending on Tools -> Options -> Mail Format
'Changing this option for outgoing mail changes the window name.
'However, AppActivate appears not to require entire name but needs up to end
'of - Message which is included in heading following the Subject string
'irrespective of the Mail Format option chosen.
AppActivate (strSubject & " - Message")
End With
End Sub
Jimmy Pena a publié un article sur le contraste entre EarlyBinding et LateBinding -
~JOL