Hi guys .. i wanted to open some of my files. like mswords that save in any of my folders. also wanted to open .txt, .jpg, html etc files.

any code for this..

i have an idea using

shell "location of exe"

but it open exe files only. i wanted to open/preview some of my documents.. any help will be much appreciated.

hi,
Try the following code:

'Declare the function to open any type of file

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

'Declare the variable of FileSytemObject to handle the files
'To get the filesystemobject select the Reference "Microsoft Scripting Runtime"
Dim f As New FileSystemObject
Private Sub Command1_Click()
CommonDialog1.ShowOpen

'To Open the Selecte File
Text1.Text = CommonDialog1.FileName
 OpenLocation (gParam_value & Text1.Text)
End Sub

'To Open the Selecte File
Private Function OpenLocation(ByVal WhichFilePath As String, Optional sParams As String = "", Optional sStartIn As String = vbNullString, Optional lngOpenMode As Long = 1) As Long
OpenLocation = ShellExecute(0, "Open", WhichFilePath, sParams, sStartIn, lngOpenMode)
End Function

Have a Great Day
Shailaja :)

Hi guys .. i wanted to open some of my files. like mswords that save in any of my folders. also wanted to open .txt, .jpg, html etc files.

any code for this..

i have an idea using

shell "location of exe"

but it open exe files only. i wanted to open/preview some of my documents.. any help will be much appreciated.

commented: thx for the help dude. ^_^ +3

perfect codes, for what i looking for.

thxx a lot manoshailu.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.