Link to home
Start Free TrialLog in
Avatar of fjkilken
fjkilken

asked on

Open Outlook file via Excel VBA

Hi
Within my custom Excel Ribbon, I want to provide a button which will open an Outlook file (.msg format) - it will need to open this file within Outlook.
(This Outlook file will be an email which will provide them help with some aspects of the Ribbon.)

How to I modify my file>open VBA code to tell Excel that this is an Outlook-type file which is being opened (and it neds to open in Outlook and not Excel)?

Thanks a lot
Fergal
ASKER CERTIFIED SOLUTION
Avatar of terencino
terencino
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fjkilken
fjkilken

ASKER

thanks - that's an option alright - just a bit messy with all the dialog boxes
Meantime, I found a solution which uses a function to Shell the appropriate application which seems to work ok

Public Function OpenWithShell(ByVal strFilePath As String) As Boolean
'Author       : Ken Puls
'Macro Purpose: To open any file in the appropriate application
    'Test for file existence to avoid Windows error message
    If Not Dir(strFilePath) = vbNullString Then
        'Open the file
        Shell ("RunDLL32.EXE shell32.dll,ShellExec_RunDLL " & strFilePath)
        OpenWithShell = True
    End If
End Function

Sub OpenFileExample()
'Author       : Ken Puls
'Macro Purpose: To demonstrate the use of the OpenWithShell function
    Dim strFullFileName As String
   
    'Set path to file
    strFullFileName = "C:\My Documents\Some Outlook Message.msg"
   
    'Check if file opened
    If OpenWithShell(strFullFileName) = False Then _
        MsgBox ("File not opened!")
End Sub