How to open a file in its default application using VBA.

R

RickW

I have an Access 2003 application in which I need to be able to open a file
in its default application in the same way that files can be opened in
Windows Explorer by their file association using the file extension.

Can this be done in VBA? I have found references to ShellExecute in VB but
this is not available in VBA. The operating system is Windows XP.
 
B

Brendan Reynolds

RickW said:
I have an Access 2003 application in which I need to be able to open a file
in its default application in the same way that files can be opened in
Windows Explorer by their file association using the file extension.

Can this be done in VBA? I have found references to ShellExecute in VB
but
this is not available in VBA. The operating system is Windows XP.


There's VBA code to call the ShellExecute API function at the following URL
....

http://www.mvps.org/access/api/api0018.htm
 
R

RickW

Thanks very much though I can't say I understand what this function is doing
- but it works!

The second arguement of fHandleFile() is a mystery. It seems you can put
pretty well any number in there as the value of lShowHow and the target
app/file either opens as maximised or restored.

The other thing is that I declared a variant type variable specifically for
calling the function fHandleFile. I presume that is correct, or at least OK?

Thanks for your help
Rick
 
M

Marco Pagliero

The second arguement of fHandleFile() is a mystery.  It seems you can put
pretty well any number in there as the value of lShowHow and the target
app/file either opens as maximised or restored.

Here is a list of all possible values of lShowHow/nShowCmd (in the
middle of the page, search for "Winuser.h". This is related to C but I
suppose the constants have the same meaning)

http://www.jpmartel.com/bu06apie.htm

Marco P
 
S

Stuart McCall

RickW said:
I have an Access 2003 application in which I need to be able to open a file
in its default application in the same way that files can be opened in
Windows Explorer by their file association using the file extension.

Can this be done in VBA? I have found references to ShellExecute in VB
but
this is not available in VBA. The operating system is Windows XP.

You can achieve this without api functions:

Application.FollowHyperlink "c:\SomeFolder\MyFile.ext"
 
R

RickW

That looks pretty clever - though I have used Brandans method now.
Here I was this morning thinking VBA couldn't do this and now there are two
methods!

Thanks to both of you.
Rick
 

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