weirddemon wrote:I'm building a program that will allow me to launch other files/programs with a button.
I'm currently doing this with
- Code: Select all
Shell ("c:\Test.txt")
I know this is an old topic but no one has given a useful solution.
No you can't really use Shell for this because Shell will only open a com, exe or bat file on its own. You can use Shell if you specify what exe you want to open the txt file.
Shell "NotePad.exe " & "c:/temp.txt", 1
You don't have to specify where NotePad.exe is because its in the Windows path.
A far better way of doing this is to use the
ShellExecute API call.
- Code: Select all
Option Explicit
Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
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
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "c:/temp.txt", vbNullString, vbNullString, SW_SHOW
End Sub
This will use the registered application used for opening txt files. This is normally NotePad.exe in Windows.
Now ShellExecute is s useful API where you can Open any file, Print any file and Email someone.
