how to execute a file type? (Resolved with thanks)
im createing my own GOOGLE EARTH KML files. These KML files are created by useing notepad then saveing as a KML extention.
When you double click on a KML file, it auto starts Google Earth and zooms to the co ords etc in the file.
I have created my own KML files which work fine, i just have to double click them to execute them. How would i do this effect in vb.
I want to execute the file, the same way as double cliking on it would.
Many thanks in advance.
Re: how to execute a file type?
Im pretty sure you need to change the default application for that program, you can do this manually but that isnt what you want.
Will look on vbCode.com...
Re: how to execute a file type?
Re: how to execute a file type?
fgp123,
Just shell to it. There are plenty of examples in the forum.
Re: how to execute a file type?
The easiest way to execute a file type is the ShellExecute API. That will open any file type that is registered in Windows.
e.g. txt - NotePad, wri - WordPad, doc - Winword, bmp - Paint etc.
VB Code:
Option Explicit
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
Const SW_SHOW = 5
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "c:\yourlocation\yourfile", vbNullString, vbNullString, SW_SHOW
End Sub
Re: how to execute a file type?
Quote:
Originally Posted by Keithuk
The easiest way to execute a file type is the ShellExecute API. That will open any file type that is registered in Windows.
e.g. txt - NotePad, wri - WordPad, doc - Winword, bmp - Paint etc.
VB Code:
Option Explicit
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
Const SW_SHOW = 5
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "c:\yourlocation\yourfile", vbNullString, vbNullString, SW_SHOW
End Sub
I get an error saying invalid use of the .Me command on that last line.
Re: how to execute a file type?
fgp123,
The function has to be in a form or you can replace the Me.hwnd with 0 if running in a module.
Re: how to execute a file type?
Perfect thank you, i had it in a module.
Re: how to execute a file type? (Resolved with thanks)
If you look at my code you will see that the ShellExecute call is made from a Command button, which should be on a Form. Me.hwnd returns the handle of the Form. :)