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

(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.
LVL 66
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAsked:
Who is Participating?
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):
Alan WarrenApplications DeveloperCommented:
I agree use the shellexecute api

Sample using ShellExecute here:

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
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.
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.