Solved

Opening the associated application

Posted on 2000-04-09
4
186 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
Comment Utility
"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
Comment Utility
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
Comment Utility
Here you go:

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

All the hard work done for ya...
0
 

Author Comment

by:scooterhead
Comment Utility
Thank you
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

772 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

13 Experts available now in Live!

Get 1:1 Help Now