3ème exemple avec un agenda
On a ici à un moment donné 8 tabulations pour se positionner dans le texte de l'agenda
Application.SendKeys "{TAB 8}", True
Option Explicit
Sub Convoquer()
Dim messagerie As Object
Dim ligne As Long
Dim invitation As Object
Dim myRequiredAttendee, myOptionalAttendee, myResourceAttendee
Const olAppointmentItem = 1
Const olMeeting = 1
Set messagerie = CreateObject("Outlook.Application")
ligne = 2
' les cellules qui seront recopiées dans le texte de l'invitation = plus simple que d'écrire un texte en html
Sheets(Cells(ligne, 9).Value).Cells.Copy
Set invitation = messagerie.CreateItem(olAppointmentItem)
With invitation
.Subject = Cells(ligne, 1).Value
.Location = Cells(ligne, 2).Value
.Start = Cells(ligne, 3).Value + Cells(ligne, 4).Value
.Duration = Cells(ligne, 5).Value
.MeetingStatus = olMeeting
If Cells(ligne, 6).Value > 0 Then
.ReminderSet = True
.ReminderMinutesBeforeStart = Cells(ligne, 6).Value
Else
.ReminderSet = False
End If
.AllDayEvent = Cells(ligne, 7).Value
' If Busy Status non spécifié, 2 par défaut (Busy)
If Len(Trim$(Cells(ligne, 8).Value)) = 0 Then
.BusyStatus = 2
Else
.BusyStatus = Cells(ligne, 8).Value
End If
ligne = 2
Do Until Trim$(Cells(ligne, 10).Value) = ""
'.Recipients.Add Cells(ligne, 10).Value
Set myRequiredAttendee = .Recipients.Add(Cells(ligne, 10).Value)
myRequiredAttendee.Type = 1 ' olRequired
ligne = ligne + 1
Loop
ligne = 2
Do Until Trim$(Cells(ligne, 11).Value) = ""
'.OptionalAttendees.Add Cells(ligne, 11).Value
Set myOptionalAttendee = .Recipients.Add(Cells(ligne, 11).Value)
myOptionalAttendee.Type = 2 ' olOptional
ligne = ligne + 1
Loop
.display ' pour visualiser avant d'envoyer manuellement
' .send ' pour envoyer directement
End With
' on se place dans le texte
Application.SendKeys "{TAB 8}", True
' recopie ici après tempo de 2 secondes
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys "^v", True
Application.CutCopyMode = False
Set myRequiredAttendee = Nothing
Set myOptionalAttendee = Nothing
Set invitation = Nothing
Set messagerie = Nothing
End Sub
'Set myRequiredAttendee = myItem.Recipients.Add("Nate Sun")
'myRequiredAttendee.Type = olRequired
'Set myOptionalAttendee = myItem.Recipients.Add("Kevin Kennedy")
'myOptionalAttendee.Type = olOptional
'Set myResourceAttendee = myItem.Recipients.Add("Conf Rm All Stars")
'myResourceAttendee.Type = olResource