How to open .msg file from Hard disk folder?

Status
Not open for further replies.

anilc59

Member
Outlook version
Email Account
Hi Friends,

I am trying to open an Outlook items from the specific folder, and then open only .msg file from the folder one by one.

Afterward I need to get the attachments from those Outlook items.

Your early reply much appriciated.

Regards

Anil Choudhary
 
You need to use windows scripting to walk the folder and can use shell commands to open it, or use Application.CreateItemFromTemplate

This sample will open the messages - i have code samples at slipstick that can get the attachments off.

Code:
Sub GetMSG() 
 
' list all files including subfolders
  ListFilesInFolder "E:\My Documents\dianep", True 
 
End Sub 
 
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
    ' lists information about the files in SourceFolder
    ' example: ListFilesInFolder "C:\FolderName\", True
   Dim FSO As Scripting.FileSystemObject
   Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
   Dim FileItem As Scripting.File
   Dim strFile, strFileType As String
   Dim openMsg As MailItem
  
  
   Set FSO = New Scripting.FileSystemObject
   Set SourceFolder = FSO.GetFolder(SourceFolderName)
 
   For Each FileItem In SourceFolder.Files
 
   strFile = FileItem.name
    
 
' This code looks at the last 4 characters in a filename 
 
' If we wanted more than .msg, we'd use Case Select statement 
 
strFileType = LCase$(Right$(strFile, 4))
 If strFileType = ".msg" Then
   Debug.Print FileItem.Path
  
 
Set openMsg = Application.CreateItemFromTemplate(FileItem.Path) 
 
openMsg.Display
   'do whatever 
 
Set openMsg = Nothing
     End If
   Next FileItem
   If IncludeSubfolders Then
       For Each SubFolder In SourceFolder.SubFolders
           ListFilesInFolder SubFolder.Path, True
     Next SubFolder
   End If
 
   Set FileItem = Nothing
   Set SourceFolder = Nothing
   Set FSO = Nothing
   
 
End Sub
 
Thanks for you reply.

but I am unable to execute the below code.

Runtime Error 438.

getting error "Object doesn't support the property or method"

Please let me know the solution. I am using EXCEL 2007.

Set openMsg = Application.CreateItemFromTemplate(FileItem.Path)
 
THe macro assumes you were using Outlook. If you are using Excel, you need to change this to identify outlook:

Set openMsg = oOL.CreateItemFromTemplate(FileItem.Path)

At the top, just above Dim openMsg As MailItem, add

Dim oOL As Outlook.Application
Set oOL = CreateObject("Outlook.Application")

Change this line to use the outlook object:

Set openMsg = oOL.CreateItemFromTemplate(FileItem.Path)

Then at the end add

Set oOL = Nothing
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Can't open same msg file more than once at the same time in Outlook 2010 Using Outlook 7
P I am getting an error msg = cannot open file access denied Using Outlook 3
B How to: Open .MSG File from Hard Drive via Code Outlook VBA and Custom Forms 2
I Outlook 2010, 2013 will not open .msg or .eml files Using Outlook.com accounts in Outlook 1
F Cannot open extracted .msg files from outlook Outlook VBA and Custom Forms 1
T Unable to open msg files in Outlook 2010 Using Outlook 11
K Outlook font corrupted in some point sizes, resets on close/open Using Outlook 2
T Cannot open .pst file Using Outlook 2
H Finding text in open email Outlook VBA and Custom Forms 12
chummy Open multiple Hyperlinks to download files Outlook VBA and Custom Forms 3
G Get current open draft message body from VBA Outlook VBA and Custom Forms 1
Rupert Dragwater How to get Outlook 365 to open from websites Using Outlook 5
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
S Leaving ActiveExplorer open for editing after Sub is done Outlook VBA and Custom Forms 0
Commodore PDF attachments started to open in Edge Using Outlook 0
T Outlook 2021 Cannot open attachments Outlook DeskTop 2021 Using Outlook 0
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
talla Can't open Outlook Item. Using Outlook 0
O Outlook on Android: after sharing / sending a news article, draft remains open. Why? Using Outlook 1
K Embedded photos no longer open with Photos or Photo Viewer Using Outlook 7
Witzker Open Contact missing in Outlook 2019 Using Outlook 2
L Cannot open PST file for first session each day Using Outlook 6
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 6
H Upon opening Outlook, make my popmail inbox open instead of outlook.com inbox Using Outlook 1
sahameed82 SharePoint calendar directly open in Outlook Using Outlook 0
N .pst archive from work will not open/import on Microsoft 365 Exchange Server Administration 0
C Outlook 2016/2019 hangs after being open for an extended period Using Outlook 4
M Where is the setting to *turn off* open calendar in a new window? Using Outlook 3
W Automatically open attachments without automatically printing them Using Outlook 0
Y Open and Save Hyperlink Files in multiple emails Outlook VBA and Custom Forms 9
J How to open OST file in Outlook 2019 & 2016 Using Outlook 1
C Can't Open Outlook 365 Using Outlook 0
D after delete mail, open the next one Outlook VBA and Custom Forms 0
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
M outlook won't open! Using Outlook 1
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
E Unable to open Outlook 2010 after adding new email account Using Outlook 4
M other user's mailbox won't open, forms disappeared Using Outlook 42
S SendFromAccount - Problem trying to test existing value in open email Outlook VBA and Custom Forms 2
J Open an outlook email by Subject on MS Access linked table with VBA Outlook VBA and Custom Forms 10
D Add Tetxbox at form open Outlook VBA and Custom Forms 1
U Catching ModuleSwitch events after "open in new window" Outlook VBA and Custom Forms 2
Andrew Quirl Open attachment, manipulate without add-on program? Outlook VBA and Custom Forms 5
S Reminder Dialog Open Button Using Outlook 2
A How to open a specific link automatically with outlook Outlook VBA and Custom Forms 13
S Outlook 2010 Cannot Open Attachments Using Outlook 14
N open the hyperlink in Outlook directly instead of browser Using Outlook 1
S Outlook does not open the .pst file created by the Outlook Using Outlook 5
A open Outlook with multiple windows. Using Outlook 0

Similar threads

Back
Top