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
| Option Compare Database
Option Explicit
'============================================================Public function===============================================================
Public Function fuOutookIsClose() As Boolean
Dim oOutlook As Object
On Error Resume Next
Set oOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If oOutlook Is Nothing Then
fuOutookIsClose = True
Else
Set oOutlook = Nothing
End If
End Function
'============================================================Public sub===============================================================
Public Sub OuvrirMail(sCompte As String, sDossier As String, sTitre As String)
On Error GoTo gestion_err
Dim oOutlook As Outlook.Application
Dim oNameSpace As Outlook.NameSpace
Dim oFolder As Outlook.Folder
Dim oAccount As Outlook.Account
Set oOutlook = New Outlook.Application
Set oNameSpace = oOutlook.GetNamespace("MAPI")
Set oFolder = oNameSpace.Folders(sCompte)
SearchAndOpenMail oFolder, sTitre, sDossier
Set oOutlook = Nothing
Set oNameSpace = Nothing
Set oFolder = Nothing
Sortie:
Exit Sub
gestion_err:
fuErr_Handler "OuvrirMail"
Resume Sortie
End Sub
'=============================================================Private sub============================================================
Private Sub SearchAndOpenMail(ByVal Fld As Outlook.Folder, sTitre As String, sDossier As String)
On Error GoTo gestion_err
Dim oLmail As Variant
Dim oSousDossier As Outlook.Folder
For Each oSousDossier In Fld.Folders
If oSousDossier.DefaultItemType = 0 And oSousDossier = sDossier Then
For Each oLmail In oSousDossier.Items
If oLmail.Subject = sTitre Then
oLmail.Display
GoTo Sortie
End If
Next oLmail
End If
SearchAndOpenMail oSousDossier, sTitre, sDossier
Next oSousDossier
Sortie:
Set oLmail = Nothing
Set oSousDossier = Nothing
Exit Sub
gestion_err:
fuErr_Handler "SearchAndOpenMail"
Resume Sortie
End Sub |
Partager