Enregistrer les photos recues par mail (OUTLOOK)

Bonjour à tous,

J'ai pas mal de notions en VBA Excel mais jamais fais de macros sur Outlook !

Voici ce que j'aimerai faire:

Chaque fois que je recois un mail d'une adresse mail bien précise, regarder si il y a une photo, l'enregistrer dans un dossier définit a l'avance puis supprimer le mail en question.

Je ne sais même pas si ce que je veux faire est possible

Je ne vous demande pas forcément de me donner un code complet de A à Z mais des pistes de reflèxions seraient les biens venues pour comment car je pars de 0 en Outlook

Petit update, mon programme prend forme j'arrive a faire ce que je veux.

J'arrive dans le vif du sujet, traiter les informations contenues dans le mail et en particulier les photos que je voudrais enregistrer.

J'ai vu qu'on pouvait manipuler les Pieces jointes mais dans mon cas les photos sont dans le mail directement pas en PJ.

Je continue de chercher une solution je meterai à jour ce topic si je trouve peut être que ca pourras aider du monde

Private Sub application_newmailex(ByVal EntryIDCollection As String)
    Dim MonMail As Object

    Set MonMail = Application.Session.GetItemFromID(EntryIDCollection)
        If MonMail.SenderEmailAddress = "lyahoo.fr" Or MonMail.SenderEmailAddress = "peyahoo.fr" Then

            'SI IL Y A UNE OU PLUSIEURS PHOTOS LES ENREGISTRER SOUS LE NOM DATE ET HEURE DE RECEPTION DANS UN DOSSIER DEFINI

        End If
        If MonMail.Subject = "" Then MonMail.Delete
End Sub

A+

J'avais l'intention de copier le contenue de mon mail et de le coller dans un nouveau Excel en espérant qu'il soit plus facile de localiser et enregistrer mes photos/images.

Problème: Je travail sur l'ordinateur de mon boulot, je n'ai pas les droits d'administrateurs et je soupconne que cela bloque alors l'accès à l'option VBA références pour activer la librairie Microsoft Excel.

Je ne peux donc pas utiliser:

Dim MonApplication As Excel.Application

Est-ce que cela condamne mon projet ou éxiste-il un autre solution ?

Bonjour Gabin37,

Le mieux je pense, est d'enregistrer ces PJ dans un dossier directement

Voici un code à adapter

Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String

' Get the path to your My Documents folder
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
On Error Resume Next

' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")

' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection

' Set the Attachment folder.
strFolderpath = strFolderpath & "\Attachments\"

' Check each selected item for attachments. If attachments exist,
' save them to the strFolderPath folder and strip them from the item.
For Each objMsg In objSelection

    ' This code only strips attachments from mail items.
    ' If objMsg.class=olMail Then
    ' Get the Attachments collection of the item.
    Set objAttachments = objMsg.Attachments
    lngCount = objAttachments.Count
    strDeletedFiles = ""

    If lngCount > 0 Then

        ' We need to use a count down loop for removing items
        ' from a collection. Otherwise, the loop counter gets
        ' confused and only every other item is removed.

        For i = lngCount To 1 Step -1

            ' Save attachment before deleting from item.
            ' Get the file name.
            strFile = objAttachments.Item(i).FileName

            ' Combine with the path to the Temp folder.
            strFile = strFolderpath & strFile

            ' Save the attachment as a file.
            objAttachments.Item(i).SaveAsFile strFile

            ' Delete the attachment.
            objAttachments.Item(i).Delete

            'write the save as path to a string to add to the message
            'check for html and use html tags in link
            If objMsg.BodyFormat <> olFormatHTML Then
                strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile & ">"
            Else
                strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" & _
                strFile & "'>" & strFile & "</a>"
            End If

            'Use the MsgBox command to troubleshoot. Remove it from the final code.
            'MsgBox strDeletedFiles

        Next i

        ' Adds the filename string to the message body and save it
        ' Check for HTML body
        If objMsg.BodyFormat <> olFormatHTML Then
            objMsg.Body = vbCrLf & "The file(s) were saved to " & strDeletedFiles & vbCrLf & objMsg.Body
        Else
            objMsg.HTMLBody = "<p>" & "The file(s) were saved to " & strDeletedFiles & "</p>" & objMsg.HTMLBody
        End If
        objMsg.Save
    End If
Next

ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

@+

Salut,

Avec un peu de bricolage j'ai réussis à adapter le code je suis trés satisfait merci !!

Je partage le code si jamais ca aide d'autres personne.

Private Sub application_newmailex(ByVal EntryIDCollection As String)
    Dim MonMail As Object

    Set MonMail = Application.Session.GetItemFromID(EntryIDCollection)
        If MonMail.Subject = "" And (MonMail.SenderEmailAddress = "ler@yahoo.fr" Or MonMail.SenderEmailAddress = "pn@yahoo.fr") Then

Dim objOL As Outlook.Application
Dim objMsg As Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String

' Get the path to your My Documents folder
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
On Error Resume Next

' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")

' Get the collection of selected objects.
Set objSelection = MonMail 'objOL.ActiveExplorer.Selection

' Set the Attachment folder.
strFolderpath = strFolderpath & "\Attachments\"

' Check each selected item for attachments. If attachments exist,
' save them to the strFolderPath folder and strip them from the item.
MonMail

    ' This code only strips attachments from mail items.
    ' If objMsg.class=olMail Then
    ' Get the Attachments collection of the item.
    Set objAttachments = MonMail.Attachments
    lngCount = objAttachments.Count
    strDeletedFiles = ""

    If lngCount > 0 Then

        ' We need to use a count down loop for removing items
        ' from a collection. Otherwise, the loop counter gets
        ' confused and only every other item is removed.

        For i = lngCount To 1 Step -1

            ' Save attachment before deleting from item.
            ' Get the file name.
            strFile = objAttachments.Item(i).FileName

            ' Combine with the path to the Temp folder.
            strFile = strFolderpath & strFile

            ' Save the attachment as a file.
            objAttachments.Item(i).SaveAsFile strFile

            ' Delete the attachment.
            objAttachments.Item(i).Delete

            'write the save as path to a string to add to the message
            'check for html and use html tags in link
            If MonMail.BodyFormat <> olFormatHTML Then
                strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile & ">"
            Else
                strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" & _
                strFile & "'>" & strFile & "</a>"
            End If

            'Use the MsgBox command to troubleshoot. Remove it from the final code.
            'MsgBox strDeletedFiles

        Next i
    End If
MonMail.Delete
ExitSub:

Set objAttachments = Nothing
Set MonMail = Nothing
Set objSelection = Nothing
Set objOL = Nothing

        End If
End Sub

Encore merci c'est top A+

Rechercher des sujets similaires à "enregistrer photos recues mail outlook"