?
Solved

Extract Attachments from .msg messages but exclude embedded

Posted on 2013-12-08
1
Medium Priority
?
582 Views
Last Modified: 2013-12-17
Hello,

I have the first draft of a vba macro but while testing i am noticing that the extraction part of this code also extracts embedded images from the email and not just the attached files.  can anyone help me to extract only the attached messages and not embedded images?


Sub Extract_Attachments()
    Dim myDir As String, myFile As String
    Dim newDir As String
    Dim count As Integer
    Dim logfile As String
    Set FSO = CreateObject("Scripting.FileSystemObject")

    'your folder with msg files here
    myDir = "c:\Burn"
    'folder for your attachments
    newDir = "c:\Burn"
    'log file
    logfile = myDir & "\log.txt"

    If FileExists(logfile) Then
      SetAttr logfile, vbNormal
      Kill logfile
    End If
   
    Set ofile = FSO.CreateTextFile(logfile)
    ofile.writeline "List of files with NO attachments"
 
    myFile = Dir(myDir & "\*.msg")
    'Application.ScreenUpdating = False
    Do While myFile <> ""
        If Not GetMsg(myDir & "\" & myFile, newDir) Then
            ofile.writeline "-->" & myFile
        End If
        myFile = Dir
    Loop
    ofile.Close
    Shell "notepad.exe " & logfile, vbNormalFocus ' open a txt document
    Shell "explorer.exe " & newDir, vbNormalFocus
End Sub
 
Function FileExists(ByVal FileToTest As String) As Boolean
   FileExists = (Dir(FileToTest) <> "")
End Function
 
Function GetMsg(ByVal OlFilePath As String, ByVal NewFilPath As String) As Boolean
    Dim oLapp, oMsg, olAtt
    Set oLapp = CreateObject("outlook.application")
    Set oMsg = oLapp.CreateItemFromTemplate(OlFilePath)
    GetMsg = False
    Dim count As Integer
    count = 0
   
    For Each olAtt In oMsg.Attachments
        olAtt.SaveAsFile NewFilPath & "\" & Left(Replace(OlFilePath, NewFilPath + "\", ""), 3) & "-" & olAtt.FileName
        count = count + 1
    Next
   
    If count > 0 Then
        GetMsg = True
    End If
    Set olAtt = Nothing
    Set oMsg = Nothing
    Set oLapp = Nothing
End Function
0
Comment
Question by:posae
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 39705559
Have you tried checking the attachment type property which has the properties:

OlAttachmentType:
     olByReference
     olByValue
     olEmbeddeditemolOLE

This method might be enough for you but if doesn't resolve correctly, (its not perfect) then assuming you are using 2007 or later you can try the PropertyAccessor in outlook for example:

olAtt.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E")


Chris
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question