import calendrier outlook public depuis excel en vba

jopont

XLDnaute Impliqué
Bonjour, je souhaiterais récupérer les données d'un calendrier Outlook situé dans un dossier public. Dans le code ci-dessous, j'ai une erreur de variable non défini. comment résoudre ce problème ? merci
Code:
   Public Function GetPublicFolder(strFolderPath)          Dim colFolders     Dim objFolder     Dim arrFolders     Dim i     On Error Resume Next     strFolderPath = Replace(strFolderPath, "/", "\")     arrFolders = Split(strFolderPath, "\")           Set objFolder = Application.Session.GetDefaultFolder(18)     Set objFolder = objFolder.Folders.Item(arrFolders(0))     If Not objFolder Is Nothing Then         For i = 1 To UBound(arrFolders)             Set colFolders = objFolder.Folders             Set objFolder = Nothing             Set objFolder = colFolders.Item(arrFolders(i))             If objFolder Is Nothing Then                 Exit For             End If         Next     End If     Set GetPublicFolder = objFolder     Set colFolders = Nothing      Set objApp = Nothing     Set objFolder = Nothing End Function
Code:
  Sub ListAppointments()       Dim golApp As OUTLOOK.Application Dim fldFolder As MAPIFolder Dim strPublicFolder As String Dim obj As AppointmentItem      Set golApp = New OUTLOOK.Application          strPublicFolder = "\Dossiers publics\Tous les dossiers publics\Agenda\Planning"                  Set fldFolder = GetPublicFolder(strPublicFolder)      Set obj = fldFolder.Items.Add(olAppointmentItem)                Range("A1:D1").Value = Array("Subject", "Start", "End", "Location")           NextRow = 2           For Each fldFolder In obj.Items         Cells(NextRow, "A").Value = golApp.Subject         Cells(NextRow, "B").Value = golApp.Start         Cells(NextRow, "C").Value = golApp.End         Cells(NextRow, "D").Value = golApp.Location         NextRow = NextRow + 1     Next fldFolder           Set golApp = Nothing     Set fldFolder = Nothing     Set obj = Nothing                Columns.AutoFit       End Sub
 

Gelinotte

XLDnaute Accro
Re : import calendrier outlook public depuis excel en vba

Bonjour,

Est-ce que c'est bien une variable qui est non définie ou Est-ce le message "Type défini par l'utilisateur non défini" ??

Si c'est cette dernière > dans la fenêtre VBE > menu Outils > Références > va cocher "Microsoft Outlook xx.x Objet Libray"

Les x correspondant à ta version de Outlook

Espérant ceci utile ...


Geli
 

Gelinotte

XLDnaute Accro
Re : import calendrier outlook public depuis excel en vba

Bonsoir,

Mon niveau VBA ne me permet pas de répondre si c'est une bonne méthode ou pas.

Comme je n'ai pas de calendrier public, je vais devoir adapter dès que je trouve un peu de temps.

En attendant, ton code bloque sur :
Set obj = fldFolder.Items.Add(olAppointmentItem) avec le no d'erreur de type 91

Où je m'interroge, c'est si tu veux lire le calendrier, pourquoi l'ajout ?? (...items.Add...)


Geli
 

jopont

XLDnaute Impliqué
Re : import calendrier outlook public depuis excel en vba

Bonjour,
J'ai essayé avec le code ci-dessous et cette fois j'ai une erreur "impossible de trouver l'objet. Microsoft Outlook."

Code:
Sub DLRendezVousOutlookDansExcel()
Dim MyOlSession As New OUTLOOK.Application
Dim MyNS As OUTLOOK.Namespace
Dim MyFolder As OUTLOOK.MAPIFolder
Dim olRendezVous As OUTLOOK.AppointmentItem
 
Dim wbClasseur As Workbook
Dim wsFeuille As Worksheet
Dim rgPlage As Range, rgEntete As Range
 
Dim i As Long, TabEntete() As Variant
 
On Error GoTo Erreur
    Application.ScreenUpdating = False
TabEntete = Array("Date & Heure début", "Objet", "Message")
 
Set wbClasseur = Workbooks.Add
    Set wsFeuille = wbClasseur.Sheets(1)
        Set rgEntete = wsFeuille.Range(Cells(1, 1), Cells(1, UBound(TabEntete)))
            rgEntete.Value = TabEntete
    'récup des objets appointment dans Calendar
    Set MyNS = MyOlSession.GetNamespace("MAPI")
        Set MyFolder = MyNS.GetDefaultFolder(olPublicFoldersAllPublicFolders)
             'chercher le bon répertoire : code à adapter
             Set MyFolder = MyFolder.Folders("\Agenda\Planning")
 
        For i = 1 To MyFolder.Items.Count
            Set olRendezVous = MyFolder.Items(i)
                    Cells(i + 1, 1).Value = olRendezVous.Start 'début de la réunion
                Cells(i + 1, 2).Value = olRendezVous.Subject 'Objet
            Cells(i + 1, 3).Value = olRendezVous.Body 'corps du message éventuel
        Next i
 
    Set rgPlage = wsFeuille.UsedRange
    'tri chronologique & mise en forme
        With rgPlage
            .Sort Range("A1"), xlAscending, , , , , , xlGuess
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlGeneral
            .WrapText = False
        End With
 
    Columns("A:C").EntireColumn.AutoFit
 
' désinstanciation
Set MyNS = Nothing
    Set MyFolder = Nothing
        Set olRendezVous = Nothing
            Set rgPlage = Nothing
        Set rgEntete = Nothing
    Set wsFeuille = Nothing
Set wbClasseur = Nothing
 
Application.ScreenUpdating = True
Exit Sub
 
'Gestionnaire d'erreur
Erreur:
    MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source
        Set MyNS = Nothing
            Set MyFolder = Nothing
                Set olRendezVous = Nothing
                Set rgEntete = Nothing
            Set rgPlage = Nothing
        Set wsFeuille = Nothing
    Set wbClasseur = Nothing
Application.ScreenUpdating = True
 
End Sub
 

jopont

XLDnaute Impliqué
Re : import calendrier outlook public depuis excel en vba

J'ai résolu le problème. En fait il faut charger successivement MyFolder comme ceci :
Code:
Set MyFolder = MyFolder.Folders("Agenda")
Set MyFolder = MyFolder.Folders("Planning")
Merci pour votre aide
 

jopont

XLDnaute Impliqué
Re : import calendrier outlook public depuis excel en vba

Bonsoir,

Le problème maintenant, c'est que dans la colonne objet et message j'ai des caractères du type retour chariots et autres (point d'interrogation encadré). Pour une utilisation ultérieure en flatfile, ces caractères ne sont pas compatibles.
Y-a-t-il une solution pour ne pas importer les retours chariots et autre ?
Merci
 

Gelinotte

XLDnaute Accro
Re : import calendrier outlook public depuis excel en vba

Bonsoir,

Si l'importation se fait bien malgré les caractères non désirés, que penses-tu d'une autre macro pour nettoyer ces caractères après l'importation ... du genre "search and replace" ... with nothing ??

Macro qui pourra être ajoutée à la fin de la première dès quelle fonctionnera bien ...


Geli
 

Discussions similaires

Réponses
2
Affichages
288
Réponses
1
Affichages
192

Statistiques des forums

Discussions
312 389
Messages
2 087 893
Membres
103 673
dernier inscrit
FmZoner