MS Access to open Outlook file

mitgore

New member
Local time
Today, 02:32
Joined
Oct 20, 2014
Messages
4
when I open a .msg file using

dim x as long
x = Shell("""C:\Program Files (x86)\Microsoft Office\Office15\Outlook.exe"" /f ""D:\mymessage.msg""")

how to access the fields "To", "CC", "Subject", "Date", "Body text", etc ?

My problem: I have a lot of files .msg (about 1000) and I want to put them in a single file (preferably in txt)

thanks for all
 
Are the files in Outlook as well? Or just saved locally?

I find it difficult to open .msg files when they aren't in an Outlook folder. I'm sure there's a way, I'm just not aware of it.

If the messages are in an Outlook folder, you can use the Outlook object library (Tools > References > Microsoft Outlook X.0 Object Library) to get those properties :

Code:
Public Sub mitgore()
 
  Dim appOutlook As Outlook.Application
  Dim objNameSpace As Outlook.NameSpace
  Dim objMailbox As Outlook.Folder
  Dim objFolder As Outlook.Folder
  Dim objItem As Outlook.MailItem
  Dim i As Long
  Dim var As Variant
 
  Set appOutlook = CreateObject("Outlook.Application")
  Set objNameSpace = appOutlook.GetNamespace("MAPI")
  Set objMailbox = objNameSpace.Folders("<Mailbox Name>")
  Set objFolder = objMailbox.Folders("<Folder Name>")
 
  For i = objFolder.Items.Count To 1 Step -1
 
    Set objItem = objFolder.Items(i)
 
    With objItem
      var = .To
      var = .CC
      var = .Subject
      var = .SentOn
      var = .Body
      var = .HTMLBody
    End With
 
  Next i
 
End Sub

If you use early-binding, the intellisense will give you all the properties associated with the MailItem object; I've just given the ones you asked for above. But you would need to create a folder in Outlook and copy all your messages there for this to work. I tried before to assign a MailItem object to a .msg file saved on a network drive and it doesn't work. Be curious to learn of a way...
 
Last edited:
Just a suggestion but it appears you might be able to use the .OpenSharedItem method for .msg files saved to a drive. Have never tried nor tested but it seems to be along the lines of :

Code:
Dim appOutlook As Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim objItem As Outlook.MailItem
 
Set appOutlook = CreateObject("Outlook.Application")
Set objNameSpace = appOutlook.GetNamespace("MAPI")
Set objItem = objNameSpace.OpenSharedItem("<Path To Your .MSG>")

Article here...

As I say, have never used it, but could work...
 
I'll try and I'll tell you. Thanks a lot. Sorry for my englisg.
:)
 
Haha - no worries - sorry for my code! (...if it doesn't work...!!) :p
 
thanks thanks thanks. It has work. I had tried for several weeks to solve this problem.
again thanks a lot.
I am from Brazil and a I don't speak english well.
 
in fact, i used your second post because I need to read a msg file directly. I don´t know to put the msg files in a folder in Outlook.
thanks
 
Great, I'm glad I could help. Best of luck with the rest of it.

And thank you for responding to confirm that it worked - this will help others (including myself) if we encounter a similar problem, that the .OpenSharedItem method will work for situations like this.

Suggest you mark the thread as 'Solved' (up the top, under 'Thread Tools')

You can hit the Thanks button too if you like... :rolleyes:
 

Users who are viewing this thread

Back
Top Bottom