Shell an Office file: Get the locations of Excel.exe, Winword.exe, Pwrpoint.ext on user's pc

Posted on 2004-10-26
Last Modified: 2008-02-01
(Continuation of

Hi all

I use the following lines to open a text file using Shell, and it works fine...

sShellPath = "Notepad.exe " & Chr(34) & sDestinationPath & Chr(34)
dbl = Shell(sShellPath, vbMaximizedFocus)

This works great for Notepad, but if I try this with any other Office document (removing the "Notepad.exe"), I get a "Invalid procedure call or argument" runtime error #5.  If I put in the full path/file of Word, Excel, etc. it works fine.

So...  either is there another way to do this without getting the file locations of Word, Excel, etc., or how can I programmatically get these file locations?

I'm using Windows XP SP2/Office XP

Thanks in advance.
Question by:Jim Horn
    LVL 41

    Accepted Solution

    Don't use Shell - you can use either of these methods to launch a file in its default handler:

    FollowHyperlink "C:\Temp\MyFile.txt"

    or use ShellExecute instead (more flexible):
    LVL 26

    Expert Comment

    by:Alan Warren
    I agree use the shellexecute api

    Sample using ShellExecute here:

    LVL 65

    Author Comment

    by:Jim Horn
    Application.FollowHyperlink, learn something new every day.

    Thanks.  For some reason, I was getting the error#5 when opening a text file in Notepad using ShellExecute, but do not get this error opening any other type of file.
    LVL 2

    Expert Comment

    Hi Jim,

    This is how I open a word document for access. I've used it in access 97 and 2000.

    Dim objWD As Object

    Set objWD = CreateObject("Word.Application")

    objWD.Visible = True

    objWD.Documents.Open "Full Path to Word Document to Open"

    Set objWD = Nothing

    Hope this helps


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    5 Experts available now in Live!

    Get 1:1 Help Now