2
votes

For those of us in a corporate environment who have no control over what email client to use, the suggested fix from Microsoft (and many other sources) on opening .eml files in Outlook 2007 doesn't help, since we typically don't have registry access and can't download add-ins.

One solution buried in the myriad frustrated forum users' posts is to use the "Run" application with the following construction:

"[path to outlook]\Outlook.exe" /eml "[path to eml file]\[Filename].eml"

Is it possible to embed this inside a macro that can be accessed from (for example) Outlook itself?

1

1 Answers

1
votes

The following code will work when run from inside Outlook 07; it prompts for a .eml file and then opens it using a shell command in the form of the "Run" prompt in the question. Unfortunately because of Microsoft's 'unique' support for VBA objects, it's not possible to call FileDialog(msoFileDialogFilePicker) from inside Outlook.

As a result, the below calls an instance of Excel to handle the dialog box. The Application.Visible = True line ensures the dialog box is brought to the front, as it can open behind the current application depending on the window environment.

You may need to edit C:\Program Files (x86)\Microsoft Office\Office12\Outlook.exe to reflect the installation location of your copy of Outlook.

Sub OpenEML()
'   Macro to open EML type outlook files
    Dim otherObject
    Dim fDialog As Office.FileDialog
    Set otherObject = CreateObject("Excel.Application")
    Set fDialog = otherObject.Application.FileDialog(msoFileDialogFilePicker)

    With fDialog
        .AllowMultiSelect = False
        .ButtonName = "Open"
        .Title = "Select an EML file"
        'Allow only eml selection
        .Filters.Add "EML", "*.eml", 1
        otherObject.Application.Visible = True
        .Show
        otherObject.Application.Visible = False
        'If some items are selected...
        If .SelectedItems.Count <> 0 Then
            fileNm = .SelectedItems(1)
        Else
            MsgBox "Nothing selected"
            Exit Sub
        End If
    End With

    Dim appNm As String
    appNm = "C:\Program Files (x86)\Microsoft Office\Office12\Outlook.exe"
    Dim retval
    'MsgBox """" & appNm & """"
    retval = Shell("""" & appNm & """" & " /eml " & """" & fileNm & """", vbNormalFocus)

End Sub