Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possable to Open a file in notepad via Shell VB6 5

Status
Not open for further replies.
Jun 15, 2003
8
US
Im trying to find a way to have my vb script open a specific text file in notepad.

Something Like
Shell "C:\path\notepad.exe" Open c:\temp.txt

Is this possable
 
You were nearly there. Just use:

Shell "C:\winnt\notepad.exe c:\temp.txt"
 
Try this

This piece of code opens any file in its default program. Like Text files in notepad, .doc files in MS Word, URLS in the browser, etc...

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 Function OpenFile(FilePath, OwnerHWnd As Long, StartupDirectory As String, nShowCmd As Long) As Long

OpenFile = ShellExecute(OwnerHWnd, "Open", FilePath, vbNullString, StartupDirectory, nShowCmd)

End Function


And Call it like this


OpenFile "c:\temp.txt", Form1.hWnd, App.Path, 1
OpenFile " Form1.hWnd, App.Path, 1

 
vbSun,
When I tried to call it, the "OpenFile" command didn't work. It kept saying that Form1 was not defined.

Thanks!

---------------------
survane@hotmail.com
 
Replace the Form1 with the name of the form where you have placed the code...

 
If you're calling it from a form use Me.hwnd

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top