Solved

Open a textfile into notepad

Posted on 2006-11-10
6
1,134 Views
Last Modified: 2008-01-09
Hi: Can any one please tell me how do i open a textfile into notepad thru VBA.

Thanks.
0
Comment
Question by:mustish1
6 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 200 total points
ID: 17919707
try this

FollowHyperlink "C:\TextFile.txt"

if Notepad is your default text editor, it will open the file in notepad
0
 

Author Comment

by:mustish1
ID: 17919711
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
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 200 total points
ID: 17919740

you can use the shell

    Dim stAppName As String

    stAppName = "C:\Windows\system32\notepad.exe C:\TextFile.txt"
     Call Shell(stAppName, 1)
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 200 total points
ID: 17920165
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
 
LVL 65

Accepted Solution

by:
rockiroads earned 200 total points
ID: 17920166
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
 
LVL 44

Assisted Solution

by:Leigh Purvis
Leigh Purvis earned 100 total points
ID: 17920367
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Microsoft Access 97 and Delphi XE2 9 53
Access 2013 - assign the value of an unbounded object to a table value 8 26
Help in SQL 13 37
IIF in access query 19 24
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question