Solved

VBA code to open a Text file from mapped drive

Posted on 2004-09-07
4
368 Views
Last Modified: 2006-11-17
hello experts,
what is the VBA code to open a Text file from a mapped drive?

i am recording receipt Numbers that the user looks at in a flat text file, and i want to have a button on the form that will open that file up in Notepad if the user needs to look at her history.

in otherwords, if the user clicks the button, i want my code to execute Notepad.exe and open up the .txt file on the user's workstation.

thanks,
mac
0
Comment
Question by:MacRena
4 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 100 total points
ID: 12000590
Throw the below two lines of VBA code behind your button.OnClick

Dim dbl As Double
dbl = Shell("c:\windows\notepad.exe {your file.txt}", vbMaximizedFocus)

...where {your file.txt} is the path/file of your text file, without the { }'s.

Hope this helps.
-Jim
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12000602
To open a specific text file, assuming you have the path in variable strPath and file in strFile:

First paste this into a new module:
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

Now call it with:
ShellExecute hwnd,"open",strFile,Chr$(0),strPath,False
0
 
LVL 4

Author Comment

by:MacRena
ID: 12000827
thanks, Jim.  that was exactly what i was needing.
thanks to you also, shanesuebsahakarn., but i'm going w/ the lesser coding.
mac
0
 

Expert Comment

by:pmcelhany
ID: 12000937
This works for me.  We use the H drive as our personal storage space on our net.
I created a small file(TextDoc.txt) and tried calling it.

    Dim stAppName As String

    stAppName = "C:\Windows\System32\Notepad.EXE H:\TextDoc.txt"
    Call Shell(stAppName, 1)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

777 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