Macro to open a outlook message file

ramkumarcn

Board Regular
Joined
Jun 21, 2011
Messages
114
Hi,

I am trying to develop a macro to open a particular outlook email file. The email file will be stored in a path in my local drive. for eg. "C:\Test\81293.msg". I need a macro to open this outlook message file referring the path mentioned.

Could you please help?

Ram
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi,

I suspect there are many ways of doing this.

I have created a text box in Sheet1 to put it in.

Tools > References Microsoft Outlook xx.0 Object Library to be selected.

Code:
Sub Msg_Open()
Dim OL As Outlook.Application
Dim Msg As Outlook.MailItem
Set OL = New Outlook.Application

'Display Open Dialog to select msg location.
  GetMsg = Application.GetOpenFilename("Files (*.msg*)," & _
    "*.msg*", 1, "Select Msg files", "Open", False)
   
'If the user cancels file selection then exit
     If TypeName(Msg) = "Boolean" Then
        Exit Sub
     End If

Set Msg = OL.CreateItemFromTemplate(GetMsg)

'Set Msg = OL.CreateItemFromTemplate(C:\Test\81293.msg)

'Create TextBox
    Set ThisDoc = ThisWorkbook.Sheets("Sheet1")
    With ThisDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, _
    10, 10, 800, 2000)
    .Name = ("Box1")
    .Select
    End With
    
    Sheets("Sheet1").Shapes("Box1").OLEFormat.Object.Text = Msg.Subject & vbCr & vbCr & Msg.Body
Set OL = Nothing
Set Msg = Nothing
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,605
Members
449,038
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top