Open a file on the client's PC using Windows API

Ever wanted to open a file on the client’s C: drive?You could use this to create reports, such as CSV text files, and then open those reports in Excel.

This uses the Windows API to open the file.

Put this in the Declare section…

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 nShowCmd As Long) As Long

Const SW_HIDE = 0

Const SW_SHOWNORMAL = 1

Const SW_NORMAL = 1

Const SW_SHOWMINIMIZED = 2

Const SW_SHOWMAXIMIZED = 3

Const SW_MAXIMIZE = 3

Const SW_SHOWNOACTIVATE = 4

Const SW_SHOW = 5

Const SW_MINIMIZE = 6

Const SW_SHOWMINNOACTIVE = 7

Const SW_SHOWNA = 8

Const SW_RESTORE = 9

Const SW_SHOWDEFAULT = 10

Const SW_MAX = 10

This is what the function call looks like…

Call ShellExecute(0&, “open”, filePath, Null, path, SW_SHOWDEFAULT)

'filePath = the absolute path of the file to open.

'path = the path of the directory to set as the default.

Here is a website for more information…