how to use SHELL to open the file_path?Code:file_path = "C:\aaa.txt"
Printable View
how to use SHELL to open the file_path?Code:file_path = "C:\aaa.txt"
There are 4 arguments - the executable path/filename, command line arguments to pass to the exe, how the window will be displayed, and whether or not you want your app to wait on the shelled program to finish before returning. Assuming you have pasted it into a bas module, you can put the following code in your button click event. This will just open up notepad and then return to your program.
Private Sub Command1_Click()
Call ShellExe("notepad.exe", "", Normal, False)
End Sub
By adding a command line argument such as the filename, this will open up a file in notepad much the same as double clicking on a text file.
Private Sub Command1_Click()
Call ShellExe("notepad.exe", " C:\boot.ini", Normal, False)
End Sub
ok? hopfully that helps
Or the more powerful ShellExecute API. It will open the file in its default associatted program. .txt will be Notepad, .htm will be the default browser, .xls will be Excel (if installed), 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 Private Const SW_HIDE As Long = 0 Private Const SW_SHOWNORMAL As Long = 1 Private Const SW_SHOWMAXIMIZED As Long = 3 Private Const SW_SHOWMINIMIZED As Long = 2 Private Sub Command1_Click() ShellExecute Me.hwnd, "Open", "C:\MyFile.txt", vbNullString, "C:\", SW_SHOWNORMAL End Sub
the above code can support only for those files inside the C drive....if the files is not in the C Drive?
Just change the filepath/filename. It works anywhere. ;)
because my system is allowed user to save files at everywhere....
but i don't know which drive will be used to save files.....
may be C,D,E drive......
Then are you also coding in that part too? If so then just set a string variable when the do the save. Then when you want to do the open you will have the filepath already.
thanks for teaching.....
Hi
I am new to VB6 programming.
I am stuck with Shell command. I want to run a EXE with command line arguments i.e.
Shell ("c:\myapplication.exe argument1 argument2")
but it does not work.
When i run it without any arguments it works.
and when itype the same is Windows Start-Run as c:\myapplication.exe argument1 argument2 then it works fine.
Please help ASAP.
regards
SAM
Please dont hijack other members threds. I see you also have your own thread so its best for any replies to your post to be posted here - http://vbforums.com/showthread.php?t=468295