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

(Continuation of http://www.experts-exchange.com/Databases/MS_Access/Q_21182166.html)

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.
-Jim
LVL 66
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAsked:
Who is Participating?
 
shanesuebsahakarnConnect With a Mentor Commented:
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):
http://www.mvps.org/access/api/api0018.htm
0
 
Alan WarrenCommented:
I agree use the shellexecute api


Sample using ShellExecute here:
http://www26.brinkster.com/alzowze/Blob_UnPack.asp?Filename=ImportBulkFiles.zip

Alan
0
 
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.
0
 
rene119Commented:
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

Rene
0
All Courses

From novice to tech pro — start learning today.