Open Text File In Notepad {RESOLVED}
My application generates a number of .Log files. All are standard text files that I can easily view in Notepad. What I'd like to do is add a menu item which, from within my program, my user to open them and view them, in notepad. I've tried:
VB Code:
Shell "c:\myfolder\mylog.log", vbNormalFocus
'and I have tried
Shell "notepad.exe c:\myfolder\mylog.log", vbNormalFocus
And neither one works. What am I doing wrong? :confused:
Re: Open Text File In Notepad
VB Code:
Shell "notepad C:\SCANDISK.LOG", vbNormalFocus
worked fine for me :ehh: Shell won't work just with the log file. It runs only exe and bat files.
Re: Open Text File In Notepad
Here is exactly what I have:
VB Code:
Private Sub mnuViewLog_Click()
Shell "notepad C:\AllState\LogFiles\Wednesday\ProcessLog_050202082323.log", vbNormalFocus
End Sub
And nothing happens. No errors. No log file. Are my file names and/or folder names too long?
Re: Open Text File In Notepad
Specify the full path (you might need the GetWindowsDirectory API function):
VB Code:
Shell "c:\windows\notepad.exe C:\SCANDISK.LOG", vbNormalFocus
Note that the Shell function is not the same as Start Menu/Run program.
Re: Open Text File In Notepad
Now I remember why I HATE useing Shell. I fixed it by tossing Shell out the nearest window and using the ShellExecute API. That never fails and I don't have to worry where Notepad is on anyone's PC! If anyone is interested:
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_NORMAL = 1
Private Sub mnuViewLog_Click()
On Error Resume Next
ShellExecute Me.hwnd, vbNullString, "C:\AllState\LogFiles\Wednesday\ProcessLog_050202082323.log", vbNullString, "C:\", SW_SHOWNORMAL
End Sub