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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a text file in notepad

Status
Not open for further replies.

Pyramus

Programmer
Dec 19, 2001
237
GB
When a button is pressed, I want it to open a text file with notepad, does anyone have any code? Ideally I want it to open without a hardcoded path to notepad as I want this to work on both Windows NT and 2000.

Thanks
 
Try this - it may be easier:
Code:
Shell "notepad.exe fred.txt", vbNormalFocus

Notepad is on your default path, so will generally be found on any OS Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
If you have a saved text file and want to open it try :
set ws=createobject("Wscript.shell")
ws.run("c:\test.txt")

-->You should enter text file address instead of "c:\test.txt".
Behnam2204@yahoo.com
BehnamPro
 
You could use the ShellExecute function to activate whatever application is associated with text files on the user's system (usually notepad):
Code:
Public Const SW_SHOWNORMAL = 1
Public Const SE_ERR_FNF = 2&
Public Const SE_ERR_PNF = 3&
Public Const SE_ERR_ACCESSDENIED = 5&
Public Const SE_ERR_OOM = 8&
Public Const SE_ERR_DLLNOTFOUND = 32&
Public Const SE_ERR_SHARE = 26&
Public Const SE_ERR_ASSOCINCOMPLETE = 27&
Public Const SE_ERR_DDETIMEOUT = 28&
Public Const SE_ERR_DDEFAIL = 29&
Public Const SE_ERR_DDEBUSY = 30&
Public Const SE_ERR_NOASSOC = 31&
Public Const ERROR_BAD_FORMAT = 11&

Public 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

.....


Dim lShellRes   As Long
    
    
lShellRes = ShellExecute(MyForm.hWnd, "open", "C:\SomeFile.txt", "", "", SW_SHOWNORMAL)


Hope that helps

Daren

Must think of a witty signature
 
pyramus.

You've had 3 more alternatives now. Any of them any good? Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top