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

  • Thread starter Thread starter RickW
  • Start date Start date
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.
 
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
 
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
 
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
 
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"
 
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
 
Back
Top