Import .msg file body to Excel

D3allamerican07

Board Regular
Joined
Jul 22, 2015
Messages
101
I am working on a process to import a folder of .msg files into excel. Each file contains a single serial number (only thing in the body) that needs to be placed on a new row. The macro below seems to work for all parts of the message except for .Body.

Goal: Loop through folder, copy body of message, paste on new row in sheet named ("Acks").

If there is a better method, please let me know! Thank you in advance!
Code:
Sub Test()

    Dim i As Long
    Dim inPath As String
    Dim thisFile As String
    Dim ws As Worksheet
    Dim olApp As Outlook.Application
    Dim MSG As Outlook.MailItem

    Set olApp = CreateObject("Outlook.Application")
    Set ws = Sheets("Acks")

    With Application.FileDialog(msoFileDialogFolderPicker)
       .AllowMultiSelect = False
            If .Show = False Then
                Exit Sub
            End If
        On Error Resume Next
        inPath = .SelectedItems(1) & "\"
    End With
    thisFile = Dir(inPath & "*.msg")
    i = 2
    Do While thisFile <> ""
        Set MSG = olApp.CreateItemFromTemplate(inPath & thisFile)
        ws.Range("A" & i) = MSG.Body
        i = i + 1
        thisFile = Dir()
    Loop

    Set myItem = Nothing
    Set myOlApp = Nothing
    
 End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,215,161
Messages
6,123,363
Members
449,097
Latest member
thnirmitha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top