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
| Public blnSearchComp As Boolean
Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As search)
Debug.Print "The AdvancedSearchComplete Event fired"
If SearchObject.Tag = "Test" Then
m_SearchComplete = True
End If
End Sub
Sub GLPI(MyMail As MailItem)
On Error GoTo Proc_Error
Dim strTicket, strSubject As String
'Variable contenant le numéro de ticket, vierge par défaut
strTicket = "None"
'Récupération du sujet du mail
strSubject = MyMail.Subject
'Vérification que c'est bien un ticket si # existe dans le sujet
If InStr(1, strSubject, "#") > 0 Then
' Récupération des 7 chiffres composant le numéro du ticket dasn la variable : strTicket
strTicket = Mid(strSubject, InStr(1, strSubject, "#"), 8)
End If
'2eme partie pour la recherche
Dim sch As Outlook.search
Dim rsts As Outlook.Results
Dim i As Integer
blnSearchComp = False
Const strF As String = "urn:schemas:mailheader:subject = strTicket" 'Variable contenant le numéro de ticket
Const strS As String = "Inbox"
'La macro crash à la ligne suivante
Set sch = Application.AdvancedSearch(strS, strF, strTicket)
While blnSearchComp = False
DoEvents
Wend
Set rsts = sch.Results 'Variable contenant le mail recherché
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.folder
Dim myDestFolder As Outlook.folder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.folders("GLPI")
Set myItem = rsts
While TypeName(myItem) <> "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend
Proc_Done:
Exit Sub
Proc_Error:
MsgBox "An error has occured in ticket number. Error #" & Err & " - " & Err.Description
GoTo Proc_Done
End Sub |
Partager