Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to open a file with it's program ?

Status
Not open for further replies.

djaypee

Programmer
Nov 30, 2001
3
BE
hi,

how do i open a file that i build in my VB program with it's corresponding program, just by clicking on a button ? example :

open xxx.htm with internet explorer
open xxx.doc with word
open xxx.txt with notepad
...

i use windows 98 and vb 6.0

thanx a lot,

djaypee
 
Do a search in this forum for ShellExecute. You should find plenty of examples of how this is done.
 
Hi,

See thread222-177509 to find the path of the program to open the file with. Then use shell or shellexecute like strongm suggests to open the document.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Public Function ShellDoc(ByVal strFile As String, frm As Form) As Long
Dim lngRet As Long
Dim strDir As String
Dim strFileExt As String
Dim strFullPath As String

lngRet = ShellExecute(frm.hwnd, "Open", strFile, vbNullString, vbNullString, vbNormalFocus)
If lngRet = SE_ERR_NOASSOC Then
'no associated program exists
strDir = String(255, " ") & Chr(0)
lngRet = GetSystemDirectory(strDir, MAX_PATH)
strDir = Left(strDir, lngRet)
'show the Openwith dialogbox
'Call ShellExecute(Me.hwnd, vbNullString, "RUNDLL32.EXE", _
'"shell32.dll,OpenAs_RunDLL ", strFile, vbNormalFocus)
strFileExt = Mid$(strFile, InStr(1, strFile, "."))strFullPath = "C:\Program Files\Accessories\wordpad.exe " & Chr(34) & strFile & Chr(34)
Shell strFullPath, vbMaximizedFocus
End If

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top