Opening Outlook Using Shell Does Not Work

T

Tal

Ok, I've got Word and Excel 2000 installed along side Outlook 2003. I
have some VBA code in a Word Add-In that uses the Shell command to open
Outlook.

Shell ("outlook.exe")

This code works in other Office configurations (all Office 2003 apps,
all Office 2000 apps, and other mixed scenarios as well, except this
one.) This line of code fails every time I try to run it with RTE 53
"File could not be found".

If I click Start -> Run and type 'outlook' or 'outlook.exe' then
Outlook opens just fine in response. But the Shell command fails in
the VBA code.

I changed the text to point to the correct Outlook location (i.e.
"C:\Program Files\Microsoft Office\Office11\outlook.exe") and this
works. Changing the code is a good workaround, but it does not prevent
the problem from occuring down the road on other machines. Does anyone
have any recommendations and can anyone tell me where office stores the
references to these shell commands?

Thanks much,
Tal
 
T

TC

There's a win32 API that returns the full pathfilename of the
executable associated with any specified document file.

So, if the ".blah" file extension was always associated with Outlook,
you could pick a random filename "my.blah", give it to that API, and
the API would return the full pathfilename of the Outlook executable.
So you could do this in yor code, at runtime, to grab that information
"on the spot", from the use's PC.

Three problems:
1. I can't for the life of me remember the name of the API !
2. I can't remember whether the test file (my.blah) has to exist on
disk, or not;
3. You'd have to know a file extension that was guaranteed to be
associated with Outlook & not with any other programs.

Someone else will doutless know 1. & 2.

HTH,
TC
 
T

Tal

Thanks for that. It seems like we were told about the API around here
as well but none of us know what it is called either. We've worked out
a solution for now. There is a registery key here:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\OUTLOOK.EXE

The key is called Path and it stores the path to the Outlook.exe file
on the system. Using WSHOM to access the registry, I simply return
that path into a string and append 'outlook.exe' to the end of the
path. This provides the Shell command the exact location of the
executable. Why I had to do this way I cannot understand, but it
works. Any advice or warnings?

Tal
 
T

TC

Just be sure that key is present in every version of Windows that you
want to support.

Cheers,
TC
 
T

Tal

So far so good. I can use the standard office commands like winword,
excel and outlook all the way back to win 98. Thx.

Tal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top