Nothing fancy, I just want to open notepad visually. Is it something like:
Shell.exe "C:\WinNT\notepad.exe"?
Printable View
Nothing fancy, I just want to open notepad visually. Is it something like:
Shell.exe "C:\WinNT\notepad.exe"?
Code:Shell "C:\WinNT\Notepad.exe"
Path may vary and to show it use vbNormalFocus, otherwise it will open minimized by default
Shell "C:\Windows\Notepad.exe", vbNormalFocus
To get the accurate windows directory check out this thread.
Code:You don't need to know the path if you use shelldef
Option Explicit
'Use Shelldef to open a file with the associated app
Private Declare Function ShellEx Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As Any, _
ByVal lpDirectory As Any, ByVal nShowCmd As Long) As Long
'
Sub ShellDef(strFileName)
Dim x As Long
x = ShellEx(Form1.hwnd, "open", strFileName, "", "", 1)
End Sub
Private Sub Command1_Click()
Dim strYourFileVariable$
strYourFileVariable = "Notepad.exe"
ShellDef strYourFileVariable
End Sub
If Notepad.exe is located in the default Windows directory, you don't even need to include the directory.
Code:Shell "Notepad.exe", 1
This should work fine too. You can also pass the name of a file to open in NotePad.
Code:Shell "NotePad " & sFileName, vbNormalFocus