if you shell a .txt file will it open it in notepad?
i ask because it would be easy to run files like that from vb if you did not need to find what had to open them
Printable View
if you shell a .txt file will it open it in notepad?
i ask because it would be easy to run files like that from vb if you did not need to find what had to open them
Shell won't open all files, it will run exe/bat files. So you could either shell notepad with the txt file as a parameter for notepad or you can use the ShellExecute API to open the txt file with the associated application.
shellexecute api?
elaborate
Examples for both options :
VB Code:
Shell "notepad C:\file.txt", vbNormalFocus
Or :
VB Code:
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_SHOWNORMAL = 1 Private Sub Form_Load() ShellExecute Me.hwnd, "open", "C:\file.txt", vbNullString, "C:\", SW_SHOWNORMAL End Sub
The ShellExecute API function is declared in this way:You could use a Sub like the following to open any file:VB Code:
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 LongVB Code:
Public Sub OpenFile(ByVal sFileName As String) ShellExecute 0, "Open", sFileName, vbNullString, vbNullString, vbNormalFocus End Sub