VBA code to open a Text file from mapped drive

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
LVL 4
MacRenaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
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
 
shanesuebsahakarnCommented:
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
 
MacRenaAuthor Commented:
thanks, Jim.  that was exactly what i was needing.
thanks to you also, shanesuebsahakarn., but i'm going w/ the lesser coding.
mac
0
 
pmcelhanyCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.