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!
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