#How to convert eml files windows#
RootWindowsFolder = InputBox("Choose a windows folder where you have your EML files",, rootWindowsFolder) RootWindowsFolder = "D:\Outlook Express EMLs folder" If rootOutlookFolder Is Nothing Then Exit Sub MsgBox "Choose a root folder for importing " ' All EML files inside this folder and in immediate subfolders will be imported.
' User chooses an Outlook root Folder, and a Windows Explorer root folder. Shell ("explorer """ & emlFolder & file & """") Total = " & countĭebug.Print "Finished importing EML files. If Right(emlFolder, 1) "\" Then emlFolder = emlFolder & "\"ĭim firstImport As Boolean: firstImport = True Sub ImportEMLFromFolder(targetFolder As Outlook.folder, emlFolder As String) ' Each EML file will be deleted after importing. ' Scans a given folder for *.EML files and import them MsgBox "Error! Could not find open inspector for importing email."ĭim m As MailItem, m2 As MailItem, m3 As MailItem While TypeName(insp) = "Nothing" ' READING PANE should be visible, or else it will not work. Sub ImportOpenItem(targetFolder As Outlook.folder)ĭim insp As Outlook.Inspector: Set insp = app.ActiveInspector ' Imports the EML open in the current ActiveInspector ' Creates a child folder in Outlook, under root folder.įunction GetChildFolder(parentFolder As Outlook.folder, name As String) ' All EML files will be imported under this folderįunction GetRootFolder() As Outlook.folderĭim NS As Outlook.NameSpace: Set NS = app.GetNamespace("MAPI")
' This method allows user to choose a Root Folder in Outlook If TypeName(insp.CurrentItem) = "Nothing" Then ' is opened by shell and we can refer to it through the ActiveInspectorįunction CloseOpenInspectors() As Booleanĭim app As Outlook.Application: Set app = CreateObject("Outlook.Application") ' All inporting is based on the assumption that the EML ' This method closes ActiveInspectors if any. Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#How to convert eml files code#
' Code by Ricardo Drizin (contact info at ) If you have any doubts or problems, let me know. PS: Sometimes you can open the EML yourself, without crashing Outlook, but according to my tests, everytime that a EML file was crashing Outlook it was something unimportant, like read receipts. In this case you can just delete the problematic EML. If it keeps crashing after restart, then probably there is a problem with the next EML file which is about to be imported. This macro crashes sometimes, but you can restart the macro at any time, and it will restart from where it previously crashed (remember, all successfully imported EML files are deleted). Finally, this email is copied into some chosen folder, and (in case of success) the original EML file is deleted. It may take a few milliseconds until Outlook opens the EML file, so the VBA waits until something is open in ActiveInspector. So I created this VBA macro which loops through some folder and opens each EML file using SHELL EXEC. Although Outlook can open EML files, there is no way to do it programatically only with VBA.