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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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