How to get properties of .msg file saved on file system

  • Thread starter Thread starter prgmdb
  • Start date Start date
P

prgmdb

Guest
Hi gurus,
I need to implement a VBA function to get properties of .msg file such as: from, to, cc, bcc, subject, and first row of body message.
I try with mailitem, but this file are stored on file system and not in an outlook folder.
I will use this function in a module of Access MDB, so I can store these information on table and find quickly email by query.
I can't use .pst file because this information will be shared and .pst file can't be accessed simultaneously by more users.

Thanks to all
 
This is a code that I complied from numerious post. OPen outlook and click on the email you want (highlight but do not open). Put this code behind a command button. You'll have to create text boxes and customize the code to work on you form.


Code:
Dim objApp As Outlook.Application
    Dim objItem As Outlook.MailItem
    Dim SndName As String, SndAddr As String, ToName As String, CCName As String
    Dim Subj As String, Rcvd As String, MsgBody As String, AtchName As String
    Set objApp = New Outlook.Application
    On Error GoTo ErrHandler
    If objApp = False Then MsgBox ("you need to open outlook"): End

    For Each objItem In objApp.ActiveExplorer.Selection
        If objItem.Class = olMail Then
            With objItem
                SndName = .SenderName
                SndAddr = .SenderEmailAddress
                ToName = .To
                CCName = .cc
                Subj = .Subject
                MsgBody = .Body
                Rcvd = .ReceivedTime
            
            End With
        End If
    Next
   
Me.Text1 = MsgBody
Me.Text3 = SndName

Me.Text7 = ToName
Me.Text9 = CCName
Me.Text11 = Subj
Me.Text13 = Rcvd
ExitHere:
    On Error Resume Next
     Set objItem = Nothing
    Set objApp = Nothing
    Exit Sub

ErrHandler:
    MsgBox ("You never opened Outlook. Open Outlook and Retry"), vbCritical, "Unexpected Error (" & Err.Number & ")"
    Resume ExitHere
 Set objItem = Nothing
    Set objApp = Nothing

I am not sure if this will work with a .msg file.
 
Last edited:
Hi bonekrusher,
thank you for your support, I confirm your supposition:
this functions works only on emailitem present in an Outlook folder, so I need to change selection source from
Outlook.Application.ActiveExplorer.Selection
to
something to reach files on folder

Do you have any other idea?
Thanks again
 

Users who are viewing this thread

Back
Top Bottom