Class: ShellExecute in Category Windows : File and Disk Operations from Total Visual SourceBook

Class that uses the Windows Shell to launch, print, or explore files or programs in VB6 and VBA with 32 and 64-bit Windows API calls.

The routines in this class allow you to use the Windows shell to perform a variety of file execution operations. For example you can copy a file or group of files and have the Windows shell provide an animated progress display. You can send files to the Recycle Bin with full confirmation support.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the CShellExecute class.
Explore Method Launches Windows Explorer open to the specified folder.
Find Method Launches Windows Explorer find feature.
LaunchDocument Method Launch a program by specifying the document or data file. For example this could be a Word document or an Access .MDB database.
LaunchEmail Method Open the program associated with email on the system.
LaunchFolder Method Open Windows Explorer to the specified folder.
LaunchProgram Method Launch a program.
LaunchURL Method Open the default Internet browser on the user's machine by specifying a URL (uniform resource locator). For example: http://www.fmsinc.com, ftp://ftp.microsoft.com, etc.
PrintDocument Method Prints a document by launching the program that is associated with the document. This is similar to what happens when you drag a document to the printer icon on the desktop.
WaitUntilClosed Method Wait until the program closes.
StillExecuting Method Determine whether the application launched with the LaunchProgram or LaunchDocument method is still running. This property is only valid if the previous method called was either LaunchProgram or LaunchDocument. If you test the value after executing one of the other methods, the property's value is always False even though it might still be executing.
' Example of the CShellExecute Class
'
' To try this example, do the following:
' 1. Create a new form
' 2. Add a command button called 'cmdTest'
' 3. Add a command button called 'cmdWaitCalc'
' 4. Run the form, and click on button to test
'
'' This example assumes that the sample files are located in the folder named by the following constant.
Private Const mcstrSamplePath As String = "C:\Total Visual SourceBook 2013\Samples\"
Private Const mcstrExampleFile As String = "testfile.txt"

Private Sub cmdTest_Click()
  Dim ShellExecute As CShellExecute
  Dim lngResult As EnumShellExecuteErrors

  Set ShellExecute = New CShellExecute

  lngResult = seeNoError

  ' Example of Explore
  lngResult = ShellExecute.Explore(mcstrSamplePath, sesSW_SHOWNORMAL)
  If lngResult <> seeNoError Then
    MsgBox "Error on Explore: " & lngResult
  End If

  ' Example of Find
  lngResult = ShellExecute.Find(mcstrSamplePath)
  If lngResult <> seeNoError Then
    MsgBox "Error on Find: " & lngResult
  End If

  ' Example of LaunchDocument
  lngResult = ShellExecute.LaunchDocument(mcstrSamplePath & mcstrExampleFile, CurDir, sesSW_SHOWMAXIMIZED)
  If lngResult <> seeNoError Then
    MsgBox "Error on LaunchDocument: " & lngResult
  End If

  ' Example of LaunchEmail
  lngResult = ShellExecute.LaunchEmail("info@fmsinc.com")
  If lngResult <> seeNoError Then
    MsgBox "Error on LaunchEmail: " & lngResult
  End If

  ' Example of LaunchFolder
  lngResult = ShellExecute.LaunchFolder(mcstrSamplePath, sesSW_SHOWMAXIMIZED)
  If lngResult <> seeNoError Then
    MsgBox "Error on LaunchFolder: " & lngResult
  End If

  ' Example of LaunchProgram
  lngResult = ShellExecute.LaunchProgram("notepad.exe", mcstrSamplePath & mcstrExampleFile, mcstrSamplePath, sesSW_SHOWMAXIMIZED)
  If lngResult <> seeNoError Then
    MsgBox "Error on LaunchProgram: " & lngResult
  End If

  ' Example of LaunchURL
  lngResult = ShellExecute.LaunchURL("http://www.fmsinc.com", sesSW_SHOWMAXIMIZED)
  If lngResult <> seeNoError Then
    MsgBox "Error on LaunchURL: " & lngResult
  End If

  ' Example of PrintDocument
  lngResult = ShellExecute.PrintDocument(mcstrSamplePath & mcstrExampleFile)
  If lngResult <> seeNoError Then
    MsgBox "Error on PrintDocument: " & lngResult
  End If

End Sub

Private Sub cmdWaitCalc_Click()
  ' Example code showing the use of StillExecuting and WaitUntilClosed

  Dim ShellExecute As CShellExecute
  Dim lngResult As EnumShellExecuteErrors

  Set ShellExecute = New CShellExecute

  MsgBox "Before Launching calc.exe"

  ' Start the calculator program
  lngResult = ShellExecute.LaunchProgram("calc.exe", "", "", sesSW_SHOWDEFAULT)

  ' Poll the StillExecuting property to see whether or not the calc.exe program is still executing.
  ' When the property returns false, break out of the loop
  If ShellExecute.StillExecuting Then
    ShellExecute.WaitUntilClosed
  End If

  MsgBox "After Calc.exe closes"

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS