Consulting

Results 1 to 3 of 3

Thread: Return metadata from Outlook .msg-files in subfolders

  1. #1
    VBAX Regular
    Joined
    Mar 2016
    Location
    Oslo
    Posts
    19
    Location

    Return metadata from Outlook .msg-files in subfolders

    I have received 500 .msg-files/Outlook items stored in multiple folders. Each file is an export of a calendar entry in Outlook. I would like to fetch metadata from each file, and print it to a structured excel-sheet, with the columns calenderitem.text, .sender, .reciever and .date, etc.

    This snippet seams to do what I'm looking for:
    http://www.litigationsupporttipofthe...from-msg-files

    But I get an error message saying "Type mismatch" when the code reaches the line "Set msg = x.OpenSharedItem(Path + FileList(Row))".

    When i debug.print the filearray in the code, it contains all the .msg-files, and both the variables path+filelist(row) returns correct file name.

    Does anyone have a suggestion on what goes wrong, or any hints of how the job might be done?

  2. #2
    I suggest that you copy the code from
    'http://www.rondebruin.nl/win/s1/outlook/openclose.htm
    to open Outlook reliably. You don't need to set a reference to Outlook in the VBA project when using the following code

    Option Explicit
    
    Sub GetMailInfo()
    'Use the following code to access Outlook
    'http://www.rondebruin.nl/win/s1/outlook/openclose.htm
    'Graham Mayor - http://www.gmayor.com - Last updated - 14 Aug 2018
    Dim MyOutlook As Object
    Dim msg As Object
    Dim x As Object
    Dim Path As String
    Dim i As Long, Row As Long
    Dim strFile As String
    
        Set MyOutlook = OutlookApp()
        Set x = MyOutlook.GetNamespace("MAPI")
        Path = "C:\FooFolder\email\"
        Row = 1
        strFile = Dir$(Path & "*.msg")
        While strFile <> ""
            Set msg = x.OpenSharedItem(Path & strFile)
            Cells(Row + 1, 1) = msg.Subject
            Cells(Row + 1, 2) = msg.Sender
            Cells(Row + 1, 3) = msg.CC
            Cells(Row + 1, 4) = msg.To
            Cells(Row + 1, 5) = msg.SentOn
            If msg.Attachments.Count > 0 Then
                For i = 1 To msg.Attachments.Count
                    Cells(Row + 1, 5 + i) = msg.Attachments.Item(i).FileName
                Next i
            End If
            msg.Close 0
            Row = Row + 1
            strFile = Dir$()
        Wend
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Mar 2016
    Location
    Oslo
    Posts
    19
    Location
    Thanx alot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •