Solved

Opening the associated application

Posted on 2000-04-09
4
187 Views
Last Modified: 2010-05-02
I have an application which uses a listview control to display icons that have associated Word documents with them and others that have TIFF images associated with them....(ex.  icon#1 = c:\windows\temp\doc1.doc icon#2 = c:\windows\temp\image1.tif).  I would like for the user to be able to double click the icon and the document or image to open in the associated application designated in the File Types list.  Any help would be appreciated...
0
Comment
Question by:scooterhead
4 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2698847
"HOWTO: Use ShellExecute to Launch Associated File"

http://support.microsoft.com/support/kb/articles/Q170/9/18.asp
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2698967
Try This.. <smile>

Syntax:

booReturn = xShellByExtension(strFileName)


<----- Code Begin ----->

Option Explicit

Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
  (ByVal lpFile As String, _
  ByVal lpDirectory As String, _
  ByVal lpResult As String) _
  As Long

Public Function xShellByExtension _
(ByVal strFileName As String) _
As Boolean

  Dim strProgram As String
  Dim lngReturn As Long
 
  ' Get Program PathName
  strProgram = Space(255)
  lngReturn = FindExecutable(strFileName, "", strProgram)
  If lngReturn < 32 _
  Then
    MsgBox (strFileName & " FILE NOT FOUND")
    Exit Function
  End If
  strProgram = Left$(strProgram, InStr(1, strProgram, Chr(0)) - 1)
 
  ' Execute Program with FileName as Parameter 1
  Dim StrCommand As String
  StrCommand = """ & strProgram & """ _
     & """ & strFileName & """
  lngReturn = Shell(strCommand, vbNormalFocus)
  If lngReturn > 0 _
  Then
    xShellByExtension = True 'Successful
  Else
    MsgBox (strCommand & vbCrLf & " PROGRAM NOT FOUND")
    xShellByExtension = False 'UNSUCCESSFUL
  End If
 
End Function

<----- Code End ----->
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 100 total points
ID: 2699384
Here you go:

http://homepage.eircom.net/~carafa/VBSamples/VBAll/shellexecute.zip

All the hard work done for ya...
0
 

Author Comment

by:scooterhead
ID: 2837194
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now