Solved

Opening the associated application

Posted on 2000-04-09
4
188 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Put text in a picture ASP.NET C# 2 56
passing parameter in sql procedure 9 61
vb6 connector to mongodb 2 81
Create Files based on Cell Values in a Range in Excel 12 37
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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