Heenan, Lambert
Lambert.Heenan at chartisinsurance.com
Fri Aug 26 08:28:53 CDT 2011
Here's one way to load direct from an MSG file on disk...
Sub LoadMailItemFromFile(strPathToMsgFile As String, oDestFolder As Outlook.MAPIFolder)
Dim myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate(strPathToMsgFile, oDestFolder)
MyItem.Move oDestFolder
Set MyItem = Nothing
Set myOlApp = Nothing
End Sub
This sub is passed the path to a file (msg) and an initialized Outlook.MAPIFolder object. It then copies the mail item into that folder, where you can do anything you need with it. Here's as simple example of it in use...
Sub LoadMsgFile()
Dim oFolder As Outlook.MAPIFolder
Dim strFile As String
strFile = "C:\SomePath\An Email File.msg"
Set oFolder = SelectOutlookMAPIFolder()
LoadMailItemFromFile strFile, oFolder
Set oFolder = Nothing
End Sub
And this is the function used to pick a folder in Outlook...
Function SelectOutlookMAPIFolder() As Outlook.MAPIFolder
Dim oParentFolder As Outlook.MAPIFolder
Dim olapp As Outlook.Application
Set olapp = CreateObject("Outlook.Application")
Set oParentFolder = olapp.GetNamespace("MAPI").PickFolder
If Not oParentFolder Is Nothing Then
Set SelectOutlookMAPIFolder = oParentFolder
End If
Set oParentFolder = Nothing
Set olapp = Nothing
End Function
Lambert
-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Mark A Matte
Sent: Thursday, August 25, 2011 5:39 PM
To: accessd at databaseadvisors.com
Subject: [AccessD] Outlook MSG files
Hello All,
I have a couple 100 .msg files.
I need to open(in access?) them and extract the info. No attachments, just text (all same format)
Anyone have any VBA tricks/advice?
Thanks,
Mark A. Matte
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com