Results 1 to 4 of 4

Thread: How to open Outlook file from Excel with VBA?

  1. #1

    How to open Outlook file from Excel with VBA?



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,284
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Try this:

    Code:
    Public Function OpenWithShell(ByVal strFilePath As String) As Boolean
    'Author       : Ken Puls (www.excelguru.ca)
    '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
    Call it like this:
    Code:
    Sub OpenFileExample()
    'Author       : Ken Puls (www.excelguru.ca)
    '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
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3
    Hi Ken
    Excellent!
    Works perfectly - thanks a million.

    Fergal

  4. #4
    Ken, you're a star. So simple. Thank you so much. I am now the office hero. All credit (well, most!) to you!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •