donderdag 11 maart 2010

Running executable from VBA / Access / Shell

When calling an executable file from VBA, you need to use CMD
function, otherwise Shell endup in a default my documents directory
and there is no way to tell it the right path.

This function calls CMD with the path parameter and the file
parameter. Path parameter also guarantees that your executable will
find any files it needs.

Public Function runSchell(Optional path As String = "", Optional file
As String = "XCheckSample.exe") As Long

Dim st As String
If path = "" Then path = CurrentProject.path & "/temp"
st = "cmd /c Start ""Title"" /wait /D """ & path & """ " & file
runSchell = Shell(st, 1)

End Function

Geen opmerkingen: