VBA: How to run another application from MS Access VBA: How to run another application from MS Access vba vba

VBA: How to run another application from MS Access


I always use ShellExecute from the Windows API when I need to execute something in VBA.
As far as I know, it works on machines without full privileges as well.

Example:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _    ByVal lpDirectory As String, ByVal lpnShowCmd As Long) As LongPublic Sub ShellEx(ByVal Path As String, Optional ByVal Parameters As String, Optional ByVal HideWindow As Boolean)    If Dir(Path) > "" Then        ShellExecute 0, "open", Path, Parameters, "", IIf(HideWindow, 0, 1)    End IfEnd Sub

Now you can call ShellEx to run pretty much anything:

'run executableShellEx "c:\mytool.exe"'open file with default appShellEx "c:\someimage.jpg"'open explorer windowShellEx "c:\"

Note that ShellEx has two optional parameters as well.
I didn't show this in the above examples, but you can:

  • pass parameters to executables
  • hide the window of the called executable


follow this link

MS ACCESS: LAUNCH AN APPLICATION FROM ACCESS 2003/XP/2000/97

here is an example of running an application in ms access

Private Sub Command1_Click()Dim myPath As StringmyPath = "C:\Program Files\mytool\mytool.exe"Call Shell(myPath , 1)End Sub

i wish it helps you


Just messing about with http://www.mombu.com/microsoft/scripting-wsh/t-vista-uac-problem-with-wscriptshell-run-method-1508617.html. I tried this on Windows 7 home PC.

Set objShell = CreateObject("Shell.Application")myPath = Environ("ProgramFiles(x86)") & "\mytool"Set objFolder = objShell.Namespace(myPath)Set objFolderItem = objFolder.ParseName("mytool.exe")objFolderItem.InvokeVerb "runas"

It might give you some ideas.