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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Sub Ouvrir_Agenda_Poseur()
Dim Email As Object
Dim objNS As Object
Dim Messagerie As Object
Dim objRecip As Object
Dim objFolder As Object
Dim Calendar_View As Outlook.CalendarView
Dim LigneActive As String
Dim f As Variant
Dim Ma_Date As Date
Nom_Calendrier_poseur = "p.gonin@zurbuchensa.ch"
Set Messagerie = CreateObject("Outlook.Application")
Set objNS = Messagerie.GetNamespace("MAPI")
On Error Resume Next 'permet de passer à la ligne suivante pour traiter l'erreur si le calendrier n'est pas trouvé
Set objRecip = objNS.CreateRecipient(Nom_Calendrier_poseur)
objRecip.Resolve
If objRecip.Resolved Then
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, 9)
'(objRecip, 6) Mail
'(objRecip, 9) Calendrier
'(objRecip, 10) Contact
'(objRecip, 11) Journal
'(objRecip, 12) Notes
'(objRecip, 13) Tâches
Set Email = objFolder.Items.Add
'Si le calendrier et trouvé mais en lecture seule (pas de modification possible)
If Not Email Is Nothing Then
Set f = ActiveSheet
LigneActive = ActiveCell.Row
If f.Cells(LigneActive, Range("TS_Suivi" & "[Intervention]").Column).Value = "" Then
Ma_Date = Date
Else
Ma_Date = f.Cells(LigneActive, Range("TS_Suivi" & "[Intervention]").Column).Value
End If
objFolder.Display 'Ouvre le calendrier partagé
Set Messagerie.ActiveExplorer.CurrentFolder = objFolder
Set Calendar_View = Messagerie.ActiveExplorer.CurrentView
' Messagerie.Application.ActiveWindow.WindowState = 2 ne fonctionne pas
Calendar_View.GoToDate "01.01.2024" 'Ma_Date
' Calendar_View.CalendarViewMode = olCalendarViewMonth 'Affiche le mois
' Calendar_View.Save
Else
MsgBox "L'agenda : " & Nom_Calendrier_poseur & vbCrLf & vbCrLf & " n'est pas accessible pour la modification.", vbExclamation, "! Oups ! Action interrompue"
End If
Else
MsgBox "L'agenda : " & Nom_Calendrier_poseur & vbCrLf & vbCrLf & " n'existe pas.", vbExclamation, "! Oups ! Action interrompue"
End If
Set Email = Nothing
Set objNS = Nothing
Set Messagerie = Nothing
Set objRecip = Nothing
Set objFolder = Nothing
Application.ScreenUpdating = True
End Sub |
Partager