• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1152
  • Last Modified:

Open a textfile into notepad

Hi: Can any one please tell me how do i open a textfile into notepad thru VBA.

Thanks.
0
mustish1
Asked:
mustish1
5 Solutions
 
Rey Obrero (Capricorn1)Commented:
try this

FollowHyperlink "C:\TextFile.txt"

if Notepad is your default text editor, it will open the file in notepad
0
 
mustish1Author Commented:
Yes it works. But is it possible if notepad is not my default editor i can still open the file into notepad only.

Thanks.
0
 
Rey Obrero (Capricorn1)Commented:

you can use the shell

    Dim stAppName As String

    stAppName = "C:\Windows\system32\notepad.exe C:\TextFile.txt"
     Call Shell(stAppName, 1)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rockiroadsCommented:
Cap's last post should do it, but u may want to use a envrionment variable or api to get the windows directory as if u run on windows 2000, default install is c:\winnt therefore code will fail if win2k installed there or your windows install directory is something altogether different.

1) Environment variable way
sFile = "c:\ppv.txt"
sRun = Environ$(SystemRoot) & "\notepad.exe " & sFile
Shell sRun,vbMaximizedFocus



0
 
rockiroadsCommented:
2) otherwise, u can do the api way - the one I prefer

add this to a module

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Public Function GetWinDir() As String
    Dim sTemp As String * 256
    Dim x As Integer
    x = GetWindowsDirectory(sTemp, Len(sTemp))
    GetWinDir = left$(sTemp, x)
End Function



Now in your code, u can do this

sFile = "c:\ppv.txt"
sRun = GetWinDir & "\notepad.exe " & sFile
Shell sRun,vbMaximizedFocus
0
 
Leigh PurvisDatabase DeveloperCommented:
For convenience... once you've added ShellExecute (fHandleFile) to a standard module
http://www.mvps.org/access/api/api0018.htm
it's hard to ever even think about application launching.  You just do it - pass the file name as you would Followhyperlink.
Of course, it textfiles weren't associated with Notepad (they almost always are) then it'd open in whatever.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now