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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| Sub Import_Outlook()
Timer1.Enabled = False
' Create Outlook Application
Dim oApp As Outlook.Application = New Outlook.Application()
' Get Mapi NameSpace and Logon
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
oNS.Logon("", "", False, True) ' TODO:
' Get all the appointments from Calendar folder
Dim oCal As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
Dim oItems As Outlook.Items = oCal.Items
MsgBox("Totall : " & oItems.Count)
Dim sSearch As String
' Use Restrict method
sSearch = "[Start] >= '" & Fdate & " 08:00 AM' and [Start] <= '01/12/3000 08:00 AM'" 'Cherche tous les enregistrement depuis la dernière mis à jour
oItems = oItems.Restrict(sSearch)
MsgBox("Totall Restricted : " & oItems.Count)
tmp = 0
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = oItems.Count
Dim oAppointment As Outlook.AppointmentItem
Dim i As Integer
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= C:\data\Calendar_net.mdb;"
ObjetConnection = New OleDbConnection
'Donner à la propriété ConnectionString les paramètres de connexion
ObjetConnection.ConnectionString = strConn
'Ouvrir la connexion
ObjetConnection.Open()
'Instancier un objet Commande
ObjetCommand = New OleDbCommand
ObjetCommand.Connection = ObjetConnection
ObjetCommand.CommandType = CommandType.Text
' Loop each item under Restrict
For i = 1 To oItems.Count
oAppointment = oItems.Item(i)
If Not oAppointment Is Nothing Then ' this is an appointment item
With oAppointment
début = .Start 'Format(.Start, "dd/MM/yyyy H:mm") 'Début
fin = .End 'Format(.End, "dd/MM/yyyy H:mm") ' Fin
date1 = Format(.End, "dd/M/yyyy") ' Date
duree = Format((.Duration / 1440) / 1, "H:mm") ' Durée
objet = .Subject ' Objet
Try
objet = .Subject.Replace("'", "''")
Catch
End Try
nom = .Location ' Nom
Try
nom = .Location.Replace("'", "''")
Catch
End Try
de = .Organizer ' De
Try
body = .Body.Replace("'", "''")
Catch
End Try
body = Replace(.Body, "&0A", vbCrLf) 'Contenu
Try
categories = .Categories.Replace("'", "''")
Catch
End Try
categories = .Categories ' Categories
End With
oAppointment = Nothing
End If
'Instancier un objet Commande
ObjetCommand.CommandText = "INSERT INTO Calendar_net ( [Date], [début], [Fin], [Durée], [Objet], [Nom], [De], [Contenu], [Categories] ) VALUES ('" & date1 & "', '" & début & "', '" & fin & "', '" & duree & "', '" & objet & "', '" & nom & "', '" & de & "', '" & body & "', '" & categories & "')"
ObjetCommand.ExecuteNonQuery()
tmp = tmp + 1
ProgressBar1.Value = tmp
Next i 'TODO pause
' Logoff
oNS.Logoff()
' Clean Up
oApp = Nothing
oNS = Nothing
oItems = Nothing
oAppointment = Nothing
End Sub |