Open .MSG File Using VBA

smartguy

Well-known Member
Joined
Jul 14, 2009
Messages
778
Hello all,

I have excel file in the below format.

i saved outlook maill in my c Drive. (.msg) based on condition i want to open the mail.

Excel file :


Excel Workbook
AB
1Mail IDStatus
225Done
326Done
Sheet1



Path : C:\mail1

if Mail Id = "25" and Status = "Done" then

Open "C:\mail1\25.msg"

Please help to provide the solution....
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I'm not 100% sure what you're asking for but if you want to loop through the worksheet opening all the filenames, you could do something like this:-
Code:
Option Explicit
 
Public Sub OpenMsgFiles()
 
  Dim iLast As Long
  Dim iRow As Long
  Dim sFile As String
  
  With ThisWorkbook.Sheets("Sheet1")
    iLast = .Cells(.Rows.Count, 1).End(xlUp).Row
    For iRow = 2 To iLast
      If .Cells(iRow, 2) = "Done" Then
        sFile = "C:\Mail1\" & .Cells(iRow, 1).Value & ".msg"
     [COLOR=green]   ' Open sFile (somehow)
[/COLOR]      End If
    Next iRow
  End With
 
End Sub
You'd have to provide the code to open the actual file as I don'y know off the top of my head how to do that.

Is that what you're trying to do?
 
Upvote 0
How are you trying to open it? What code are you using?

Or is it that you don't know how to open it at all?

Have you tried:-
Code:
Shell "notepad " & sFile

Or do you want to open it in your default mail client?
 
Upvote 0
Macro Working fine. but it was open in Notepad.....

I want to Open the file in mail client......
 
Upvote 0
Place this at the top of your code module. It must be a standard code module, not a worksheet code module:-
Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWMINIMIZED As Long = 2

And use this to open the file:-
Code:
ShellExecute 0, "Open", sFile, "", "C:\Mail1", SW_SHOWNORMAL
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,718
Members
452,939
Latest member
WCrawford

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