PDA

View Full Version : GetExePath for VBA Access



antonin
05-31-2006, 03:13 AM
How can I get the Exe path from the file path (i.e., its extension) to run the Shell command on the file (automatically selecting the application to run it, of course, if the extension is registered with the system)

(I have a database of e-mail messages where full path of the attachments are saved and would like to open these attachments by just clicking a button)

TiA

Antonin

boneKrusher
05-31-2006, 04:53 AM
Are you looking to just open a file of any type from within access? If so you can do this with out the shell command.

Apps
05-31-2006, 04:53 AM
Hi Antonin,

Use the below custom function to cycle through the filename from the right until it finds the ExePath marker (".").


Function STRIPFILE(xPath As String)
'=====================================
'identifies Exe name from filepath
'=====================================
Dim z As String, z2 As String
z = "."
'definitions -------------------------
Dim i As Integer, j As Integer
i = Len(xPath)
j = 1
'loop thru filename ------------------
Do
z2 = Right(xPath, j)
'when find z then exit loop
If Left(z2, 1) = z Then Exit Do
j = j + 1
Loop
'-------------------------------------
'result
STRIPFILE = Right(xPath, j - 1) '< or use 'j' to
'show z(".") - e.g ".xls" instead of "xls"
End Function

Sub xTest1()
x = STRIPFILE("nothing.xls")
Debug.Print x
End Sub


xTest1 gives you an example.

Then use nested Ifs/ElseIfs or Select Case to map each STRIPFILE result to the relevant application to utilise for your Shell command.

Hope this is ok :thumb

Apps
05-31-2006, 04:57 AM
Sorry, have just noticed that this was in Access and not Excel - give the Function a go anyway, I don't see any reason why it wouldn't work.

Will try to pay more attention next time - am half asleep today .... !! =)

antonin
05-31-2006, 05:03 AM
I need to know: how can I run a file and let the system choose the proper application from the file name (i.e. extension). I am not asking for getting the extension string from the filename string, that is more or less easy (thanks anyway)

Antonin

ChrisO
05-31-2006, 08:02 PM
G?day Antonin

The ShellExecute function is described here (http://www.allapi.net/apilist/ShellExecute.shtml).

You may also like to look at the Application.FollowHyperlink method.

Hope that helps.

Regards,
Chris.