| | | | FindExecutable sFile, vbNullString, sEXE txtEXE = sEXE End Sub | | | | | | The ShellExecute function can either open a file or print it. The VB declaration is: | | | | | | 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 | | | | | | As an example, referring to Figure B-1, the code behind the Execute button is: | | | | | | Private Sub cmdExecute_Click() Dim sFile As String Dim lResp As Long sFile = txtFile lResp = ShellExecute (Me.hwnd, "open", sFile, vbNullString, _ vbNullString, SW_SHOWNORMAL) End Sub | | | | | | Note that the documentation indicates that the final parameter should be set to 0 for a document file, but this does not seem to work on my system! | | | | | | The ShellExecute function can also be used to open a folder in Windows Explorer, using one of the following syntaxes, which differ only in the second parameter: | | | | | | ShellExecute(handle, vbNullString, <PathToFolder>, _ vbNullString, vbNullString, SW_SHOWNORMAL); ShellExecute(handle, "open", <PathToFolder>,_ vbNullString, vbNullString, SW_SHOWNORMAL); ShellExecute(handle, "explore", <PathToFolder>, _ vbNullString, vbNullString, SW_SHOWNORMAL); | | | | | | The first two versions of ShellExecute will open the specified folder. For instance, the code: | | | | | | ShellExecute Me.hWnd, "open", "d:\temp", _ vbNullString, vbNullString, SW_SHOWNORMAL | | | | | | displays the dialog shown in Figure B-2. | | | | | | The third call to ShellExecute opens a new Windows Explorer window and displays the contents of the specified folder. | | |