Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


reading msg file?

reading msg file?

reading msg file?

Hi,  I am new to this forum.  I tried do search on using vba to read msg files I drag out from outlook.  The only ones I found were reading the msg files as regular text file.  I also tried searching on the web, but without any luck :(.  i am wondering if there an expert out there who can let me know if there's any other way to deal with msg files?  What I wanted to do is sharing emails in a PST file.  I am trying to save the sender, reciever, subject and body into SQL and be able to do search easier for multiple users.  I noticed when I open the PST, it's locked.  Using third party software to share is not an open option for me.  So I have to try store everything in SQL and let users be able to search thro the emails in the PST files.  I would be appreciated if anyone can point me to the right direction; eighter on reading msg (not as text file) or a better way to share emails in the PST file.  Thank you in advance.

best regards,


RE: reading msg file?

Thank you kindly for your reply Remou.  I already have everything sort out.  What I did was drag all the message out from the PST file and read the properties of each msg file.  using the msdn library example.  It's actually not so bad.  My only question left right now is every time i access try read a msg file, outlook gives me a warning message relating something is trying to access the server.  I am still doing searches on the issue.  I will post result when I found out how.  The code block i have below reads all msg files and gets the properties off the file and stores into a table in sql server.  I hope anyone has any use to the code :)


Public Sub getFiles(Path As String)
    Dim fso, f, fc, f1, sqlStr
    Dim myitem As Outlook.MailItem

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(Path)

    'read all files in present folder
    Set fc = f.Files
    For Each f1 In fc
        Set myitem = Outlook.Application.CreateItemFromTemplate(Path & "\" & f1.Name)
        sqlStr = "insert into tblEmails (FileName, Sender, ReceiverEmail, Receiver, ReceivedDate, Subject) Values ('" & Replace(Path & "\" & f1.Name, "'", "''") & "', '" & Replace(myitem.SenderName, "'", "''") & "', '" & myitem.SenderEmailAddress & "', '" & Replace(myitem.To, "'", "''") & "', '" & myitem.ReceivedTime & "', '" & myitem.Subject & "')"

        DoCmd.RunSQL sqlStr

    'read all subfolders
    Set fc = f.subfolders
    For Each f1 In fc
        getFiles (f & "\" & f1.Name)
    'Set fso = Nothing
    'Set f = Nothing
End Sub

RE: reading msg file?

Hello again everyone, does anyone know how to turn off that pop up when you use MAPI?  I mean the pop up asking for your permission to use the outlook session.  I tried searching, but not sure what to search for.  if anyone can answer, i would be much appreciated.  Thank you

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close